+ 1
Can anyone explain the output?
#include <iostream> using namespace std; int main() { int x=1,y=1,z=1; cout<<(++x||++y&&++z); cout<<x<<y<<z; return 0; }
6 ответов
+ 2
I’m not sure how C++ handles integers as booleans, but the second cout will output 222 because x y and z were incremented in the line before.
+ 1
No, the compiler doesnt have to test z because the OR-Condition will always be true if one operand, here x, is true. Whether z is true or false simply doesnt matter for the compiler, so he skips checking it. Did you read through the post I linked? I explained it in detail there...
0
Here you find a similar case that should aswer your question:
https://www.sololearn.com/discuss/992610/?ref=app
0
i can't understand why z is not incremented
0
In ++x||++z only x is increased and result is one but after that to evaluate and second condition must be checked i.e ++z
0
ohk now i understand the precedence of && is greater than ||. Thanks for helping