Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

C++ help please. x = 1; if int y = (++x)++ how do I evaluate this?

OpenStudy (bibby):

``` 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 ```

OpenStudy (e.mccormick):

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.

OpenStudy (rsmith6559):

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.

OpenStudy (e.mccormick):

Ah, true. I missed the ( ) requirment. The joy of tricky questions...

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!