need help in understanding why y comes 1 instead of 2 according to me from statement 1.Code:#include<stdio.h> void main() { int x, y, z; x=y=z=1; z = (++x || ++y && ++z); //statement 1 printf("x = %d\ty = %d\tz = %d",x,y,z); }
need help in understanding why y comes 1 instead of 2 according to me from statement 1.Code:#include<stdio.h> void main() { int x, y, z; x=y=z=1; z = (++x || ++y && ++z); //statement 1 printf("x = %d\ty = %d\tz = %d",x,y,z); }
My teacher told me that it's answer is hidding in OR truth table, but i can't find any source to find its answer.
You might have misheard your teacher: rather, the answer lies in the fact that && has a higher precedence than || and that for || and &&, once the left operand's value is found to be sufficient to determine the value of the expression, the right operand is not evaluated (i.e., a "short circuit" behaviour).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)