Short circuit evaluation with both && || operator

The expression 5 || 2 && ++x is equivalent to 5 || (2 && ++x) due to operator precedence.

The run time evaluates the expression 5 || 2 && ++x from left to right.

As we know in OR if first condition is true it will not check the second condition.
So here 5 evaluated as true and so (2 && ++x) will not be performed.

That’s why x will remain 0 here.

Leave a Comment