+ 1

Plz explain output of code?

C++ challenge question https://code.sololearn.com/c4YPVZo86u2w/?ref=app

2nd Jan 2022, 3:14 AM
gaurav kumar
gaurav kumar - avatar
5 Respostas
+ 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.
2nd Jan 2022, 3:39 AM
Emerson Prado
Emerson Prado - avatar
+ 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
2nd Jan 2022, 3:43 AM
gaurav kumar
gaurav kumar - avatar
+ 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
2nd Jan 2022, 4:11 AM
Emerson Prado
Emerson Prado - avatar
+ 1
2nd Jan 2022, 4:12 AM
gaurav kumar
gaurav kumar - avatar
+ 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
2nd Jan 2022, 4:19 AM
FanYu
FanYu - avatar