I don’t know if anyone could kindly explain this code for me?
unsigned int x = 0;
(x ^= x ) || x++ || ++x || x++;
printf("%d\n", x);
when I compile this on my computer using gcc 4.2, the output is 2.
Originally i thought maybe this behavior is unspecified but then i figure || will have lower precedence over other operators, so shouldn’t the answer be 3? Since there are three “++”.
Can someone explain? Thanks
(x ^= x)is evaluated and it yields 0, therefore:(x++)is evaluated and it yields 0, therefore:(++x)is evaluated and it yields 2, therefore it stopsIt all boils down to one rule:
||only evaluates its right side if its left side is false.