Why does the following expression evaluate to 0?
i > --i
Suppose i = 5. Evaluating the expression from left to right, we evaluate the left operand (i) to get 5 and we evaluate the right operand (–i) to get 4. So the expression about should evaluate to 1. But when I compile it with gcc and run it, it always evaluates to 0. Is there a flaw in my thought process?
It’s simply undefined behaviour, since you are modifying the value of
ias well as reading it without an intervening sequence point. The relational operator<does not introduce a sequence point.From C11, 6.5(2):