473,795 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

&& and || Operator precedence enforcement

Hi Folks,
This question may well have been asked and answered before. But, sorry
that I couldn't find one from the archives.

I typed up this program and compiled it with gcc 3.3.2
main() {
int i = -3,j= 2,k=0,m;

m = ++i || ++j && ++k;
printf("\n%d %d %d %d\n",i,j,k,m);
}
and got the output to be
-2 2 0 1

I presumed that the answer should have well been
-3 3 1 1

as ++j and ++k would first be evaluated and && operator applied to
obtain the result to be TRUE (3 && 1). Hence, ++i wouldn't be evaluated
as one part of || goes TRUE.

The ANSI C specification clearly states that && has precedence over ||.

Could someone explain why this strange "-2 2 0 1" output for the program
is obtained?

Cheers
Vivek
Nov 14 '05
20 8156
In <40************ ***********@new s.free.fr> Nudge <de*****@kma.eu .org> writes:
Dan Pop wrote:
Grumble wrote:
I think your clock is incorrectly set.

The original message is dated 14:34:18 GMT (1) and your reply is dated
13:56:05 GMT (2).

(1) Date: 19 Jan 2004 06:34:18 -0800
(2) Date: Mon, 19 Jan 2004 13:56:05 GMT


How did you decide that the original message was correctly time stamped?


The original message showed up on my system when I downloaded new
messages at approximately 14:40:00 GMT.

Then Pete's and Christopher's messages showed up on my system when I
downloaded new messages at approximately 14:55:00 GMT.

When Richard's message showed up 5 minutes later, I figured it was
more probable that the first 3 were correctly time-stamped, and it
was Richard's clock which was incorrectly set.

Are you satisfied with my answer? :-)


Looks like a perfect non-sequitur to me. There is no connection between
the order Usenet messages arrive at one site and the order in which they
were posted. So, it is perfectly possible that the original message was
incorrectly time stamped and that Richard was the first person to post a
reply to it, even if you got other replies before his. No need to assume
that the other messages were incorrectly time stamped in order to validate
this scenario.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
11375
by: William | last post by:
Original question: "Give a one-line C expression to test whether a number is a power of 2. " Answer: if (x && !(x & (x-1)) == 0) My question: Why does this expression work?
17
3065
by: orekinbck | last post by:
Hi There Say I want to check if object1.Property1 is equal to a value, but object1 could be null. At the moment I have code like this: if (object1 != null) { if (object1.Property == desiredValue)
8
2819
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);" TextBox2.Attributes.Add("onKeyPress", jscode) You will notice that jscode contains the JavaScript Logical And operator (&&). However, ASP.NET renders this as &amp;&amp; in the code that is
9
3749
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T'); printf("%d", a); /* code end */ 2
9
1755
by: find clausen | last post by:
How can I use this: if (!zxmes && self.name != "menu") and add if (zmes == 1) if (!zxmes && self.name != "menu" || zmes == 1) and make it work.
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.