C++ help please. x = 1; if int y = (++x)++ how do I evaluate this?
``` int y = (++x)++ ``` gets interpreted as ``` int y = (++x); x++; ``` which in turn is processed in the following order: ``` (++x); //x->2 int y = x; //y=2 x++; //x=3 ```
Because of the "if" there, it will return true if the assignment happens. So as long as x exists and can use the ++ incrementors, then y will be assigned and therefore return true as a result and the if will succeed. But if x does not exist, then the assignment will fail and it will be false.
As written, it will evaluate as a syntax error, it won't compile. if requires parenthesis in C derived languages. if( y = (++x)++ ) Then e.mccormick is right, and it happens like bibby explained.
Ah, true. I missed the ( ) requirment. The joy of tricky questions...
Join our real-time social learning platform and learn together with your friends!