Int x=1,y=2,z=0; if(x!=y>z) cout<<"1"; else cout<<"0"; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Int x=1,y=2,z=0; if(x!=y>z) cout<<"1"; else cout<<"0";

Why answer is 0 ?

26th Jan 2021, 12:52 PM
Vaishali Jha
3 Answers
+ 2
y>z returns true and x!=true is obviously false .
26th Jan 2021, 12:56 PM
Abhay
Abhay - avatar
+ 2
Operator > has higher precedence over operator !=. So `y > z` is evaluated first, and then the result (true or value 1) is used as the right hand side operand for evaluation of `x != z`. Obviously `x != 1` is evaluated as false because <x> value is 1, and that's how we ended up executing the `else` block.
26th Jan 2021, 1:36 PM
Ipang
+ 1
Int x=1,y=2,z=0; if(x!=y>z) cout<<"1"; else cout<<"0"; You defined two variable and in if condition you have written if(x!=y>z) here y>z which is true so it will return 1 so If(1!=1 ) here 1==1 so it true but here u have written not equal (!=) Which will make condition false ao else part will be execute and result 0 will be print.
26th Jan 2021, 1:04 PM
A S Raghuvanshi
A S Raghuvanshi - avatar