The statement;
d = ++a && ++b || ++c;
Is grouped left to right (given the precedence of &&
);
d = (++a && ++b) || ++c;
Hence, when evaluating the &&
, since the first operand is true (the ++a
), the second is evaluated (the ++b
). At this point, the result of this logical AND is true
; hence the logical OR is true and its second operand is not evaluated (the ++c
).
This behaviour is guaranteed and is commonly known as short circuit evaluation. The wording for this in the standards for C++ and C is listed here, in this answer; briefly reproduced here for C++;
§5.14 Logical AND operator
1 The &&
operator groups left-to-right. The operands are both contextually converted to bool (Clause 4). The result is true if both operands are true and false otherwise. Unlike &
, &&
guarantees left-to-right evaluation: the second operand is not evaluated if the first operand is false.
§5.15 Logical OR operator
1 The ||
operator groups left-to-right. The operands are both contextually converted to bool (Clause 4). It returns true if either of its operands is true, and false otherwise. Unlike |
, ||
guarantees left-to-right evaluation; moreover, the second operand is not evaluated if the first operand evaluates to true.