0

Can someone please explain this code to me ?

I saw this code in the regular challenges I play and could not fathom the final output , so I wrote the code into the code playground to check if the output is correct , and it was. I don't understand how the values of y and z don't increment while on the contrary the value of x does. https://code.sololearn.com/c9TZEMq15U70/?ref=app

17th Jan 2018, 5:01 AM
Sylvester Saxena
Sylvester Saxena - avatar
4 Answers
+ 4
Compiler precedence is (++x||(++y&&++z)) so since first is true no need to look at second.
17th Jan 2018, 5:40 AM
John Wells
John Wells - avatar
+ 3
cout<<(++x||++y&&++z)<<endl; because x is not 0 the expression is true so the other side of the or does not execute as it can't change the true already reached.
17th Jan 2018, 5:07 AM
John Wells
John Wells - avatar
+ 2
Oh ! I need to go through C++ Operator Precedence once again ! Thank you so much @John !
17th Jan 2018, 6:01 AM
Sylvester Saxena
Sylvester Saxena - avatar
+ 1
But @John , aren't the ++x || ++y supposed to be executed together ? Like { (++x || ++y)&&++z } ??
17th Jan 2018, 5:18 AM
Sylvester Saxena
Sylvester Saxena - avatar