||
or logical OR operator has a short-circuit property. It only evaluated the RHS is the LHS is FALSY.
In your case, the evaluation of ++x
produces a value of -2
, which is not FALSY (0). Hence, the RHS is never evaluated.
To break it down:
m = ++i || ++j && ++k;
>> m = (++i) || (++j && ++k);
>> m = (-2) || (++j && ++k);
>> m = 1 // -2 != 0
So, only the value of m
and i
are changed, remaining variables will retain their values (as they are not evaluated).
That said, the result of the logical OR operator is either 0
or 1
, an integer value. The result is stored in m
, in your case.
9
solved Logical Operators and increment operators [duplicate]