Hi, while I was helping in some programming exercises, there was this problem:
I checked the precedence table of c operators, and saw that && has higher precedence than ||, so I guessed that the output for the variables would be: i:2 j:1 k:2 (j would be short-circuited).Code:int i = 1, j = 1, k = 1; printf("%d ", ++i || ++j && ++k); printf("i:%d j:%d k:%d", i, j, k);
But when we tested it, the output was: i:2 j:1 k:1.
Basically the || was evaluated first, and I didn't understand why.
What's going on?



LinkBack URL
About LinkBacks




