The logical &&
and ||
operators fully evaluate the LHS before doing any evaluation of the RHS.
In the code shown, since ++i
is -2
, the LHS of the ||
evaluates to true (1
) and the RHS is not evaluated. Therefore, neither j
nor k
is incremented. The printed result follows: m
was assigned 1
, i
became -2
, and j
stayed as 2
and k
stayed as 0
.
The only remaining issue is that &&
binds tighter than ||
, so:
a || b && c
is equivalent to:
a || (b && c)
so if a
evaluates to true (non-zero), then neither b
nor c
is evaluated.