Precedence of && over || [duplicate]

The || operator short-circuits – if its first operand evaluates to true (nonzero), it doesn’t evaluate its second operand.

This is also true for &&, it doesn’t use its second operand if the first one is false. This is an optimization that’s possible because any boolean value OR true is true, and similarly, any boolean value AND false is always false.


OK, so you’re confusing precedence with evaluation order. Nothing is contradictional here at all:

++i || ++j && ++k

is grouped as

(++i) || (++j && ++k)

since && has higher precedence. But then the LHS of the OR operation is true, so the whole RHS with its AND operation is discarded, it isn’t evaluated.


To your note in the edit: yes, you’re wrong: operator precedence is still not the same as order of evaluation. It’s just grouping.

Leave a Comment