posted 15 years ago
An operator with higher precedence will associate with its operands first, but that doesn't mean the operator is executed first:
true || true && ++a == 3
is the same as:
true || (true && ++a == 3)
This will then evaluate the left operand of ||, which is true, and since || is a short circuit operator, the right operand will never be evaluated.
In contrast,
true && true || ++a == 3
is the same as:
(true && true) || ++a == 3
This won't increment a either though.
Also, notice that if || had higher precedence than &&, then
true || true && ++a == 3
would be the same as:
(true || true) && ++a == 3
In that case, a would be incremented and become 4.
All code in my posts, unless a source is explicitly mentioned, is my own.