consider this code (C ++):
int x = -4 , y = 5 ; bool result = x > 0 && y++ < 10 ;
first the expression (x> 0) will be evaluated, and therefore (x> 0 = false) and due to the evaluation of the short circuit, the other expression (y ++ <10) will not be evaluated, and the value of y will remain 5.
Now consider the following code:
int x = -4 , y = 5 ; bool result = (x > 0) && (y++ < 10) ;
it is expected that the expressions in parentheses will be evaluated first so that before performing a logical AND, the expression (y ++ <10) would be evaluated, and the value of y would be 6, but the reality is that the value of y will remain equal to 5. which even in parentheses, the evaluation is short-circuited, and the expression (y ++ <10) is ignored.
What is the explanation for this case ?!
source share