(x---1) == (x-- -1)
, because the compiler first tries to select a larger token, so --- interpreted as -- and -
The expression x-- - 1 means the first 1 subtracted from the current x value due to - minus the operation. Then, the x value decreased by 1 due to the postfix decrement operator -- .
For example, before the first iteration x = 3 , therefore, under condition 2 (i.e. 3 - 1 ) after that x decreases and before the next iteration x = 2 .
x = 3 , i =0 ;
- 1 iteration:
while(2) , and in loop i becomes 1
x = 2 , i = 1;
- 2 iteration:
while(1) , and in loop i becomes 2
x = 1 , i = 2;
- Now
x - 1 = 0 , which gives while(0) , and the loop breaks and i do not increase.
So, after the exit of the cycle i : 2
pay attention to one more point: i does not increase as a loop break, because i++ in while-block {} , but x reduced to 0 . After the loop, if you type f x , then the output will be 0 .
source share