Hi horace!!
I get what you said and in fact i came up with this explanation myself initially....what got me really confused is this theory doesnt seem to hold for the following code; its pretty much the same code, with the zero changed to a 1:
int i=0;
7||1&&++i;
of what i gathered from your post, the compiler goes about this expression in the following way :
&& has higher precedence compared to ||, so we have 7||(1&&++i). while tryin to evaluate 1&&++i (i reckon theres is no short circuit evaluation that comes into the picture here) the value of i should have changed. However its value still remains 0!!This is precisely what is confusing me.....
thinking about it again we rememebr C guarantees that the operands of binary logical operators are evaluated from left to right. so
-
7||(0&&++i);
-
7||(1&&++i).
-
in both cases the || is evaluated and it true so (1&&++i) or (0&&++i) is never eveluated, so i = 0
now consider
0 is false so 1&&++i is evaluated
1 is true so ++i is evaluated (i is incremented to 1)
and the overall expression is true
now
0 is false so 0&&++i is evaluated
0 is false so ++i is not evaluate
the overall expression is false
do you rekon we are there now?