+ 1
Plz explain output of code?
C++ challenge question https://code.sololearn.com/c4YPVZo86u2w/?ref=app
5 Réponses
+ 1
In expression "++x||++y&&++z", the "++x" evaluates to true, so "++y&&++z" aren't executed.
Boolean operations, in many languages, stop executing when the result can't change. True OR anything is always true, so there's no need to evaluate the remaining operations.
+ 1
Emerson Prado but isnt that would be wrong .
what if in place of z its 0.so if here it executes only till x then result will be 1 but it should be 0.its wrong.
shouldnt it execute fully?make it more clear plz
+ 1
The AND operator has higher precedence, so it's interpreted as:
++x || (++y && ++z)
This way, being "++x" true, what's inside the parenthesis becomes irrelevant.
https://en.cppreference.com/w/cpp/language/operator_precedence
+ 1
Emerson Prado thanks
+ 1
cout<<(++x&&++y&&z++); // output 1
You may try this.
boolean and boolean, search False, got it and end
boolean or boolean, search True, got it and end