@cigien answer is correct but I'd like to add detail to it.
When you do if(a++ == a)
, the left side evaluates to a
before increment. That is clear. But what is not so clear is: does the left or right side of ==
gets evaluated first?
If it is the left side first, then a
will be evaluated, then incremented, for the left side. Then a
will be evaluated again (+1) so the two expressions won't be equal.
If it is the right side first, then a
will be evaluated, for the left side. Then a
will be evaluated again (same value), then incremented so the two expressions will be equal.
Similarly, when you pre-increment, if the left side evaluates first, then both will see incremented b, hence false. But if the right side evaluates first, then only the left side will see the incremented b, hence false.
HTH.