Why does “++x || ++y && ++z” calculate “++x” first, even though operator “&&” has higher precedence than “||”

Huh?

If you’re saying that && binds tighter than || (which is true), the expression is then equivalent to

++x || (++y && ++z)

Since || short-circuits, it needs to evaluate the left-hand side first.

If you mean that it ought to be equivalent to

(++x || ++y) && ++z

The same is still true, since && also short-circuits, meaning the || needs to be evaluated first, which in turn makes ++x the first thing to evaluate.

Leave a Comment