Results 1 to 4 of 4
Hi all,
Please take a look at the following code snippet.
int x = 0, y = 5, z;
z = x && (y = 10);
The value of y ...
- 10-14-2009 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 12
How is the following expression evaluated?
Hi all,
Please take a look at the following code snippet.
int x = 0, y = 5, z;
z = x && (y = 10);
The value of y after the evaluation of the above statement is 5.
My question is: Why isn't it 10?
() have a higher precedence than &&, in which case y = 10 should be evaluated before the && operator is.
So according to me the following should have happened
1) y = 10
2) x && y => 0 && 10
3) z = 0
leaving the value of y to be 10
But why is y being 5 after? Why is GCC being weird?
Thank you.
- 10-14-2009 #2
Try compiling with the -S switch and see what was assembled...
gcc -S filenameMake mine Arch Linux
- 10-14-2009 #3Linux Newbie
- Join Date
- Sep 2004
- Location
- UK
- Posts
- 160
Best guess it's doing a short circuit evaluation because && is a logical operator, probably caused by optimizations. try turning off optimzations.
In a world without walls and fences, who needs Windows and Gates?
- 10-14-2009 #4


Reply With Quote
