+ 1

Why is output 1 ??

int x=0; int y=0; int z=(x==y); cout<<(z==(y!=z));

24th May 2020, 2:51 PM
Karan Dewangan
Karan Dewangan - avatar
3 Antworten
+ 4
• (x == y) returns 1 (true) if x is equal to y, which is the case here. • In the next line, (y != z) returns 1 (true) because the value of y is zero while z is one. • Now, z == (y != z) is an equivalent expression to (z == 1) which returns 1 as it's true. Something to keep in mind would be to use the code playground and post a link here instead of writing it in the Q/A section. (Not really needed for this particular one, just a suggestion.)
24th May 2020, 3:07 PM
Harsh
Harsh - avatar
+ 3
z=1 y!=z returns 1 and z==1 is true so answer is 1
24th May 2020, 2:56 PM
Abhay
Abhay - avatar
+ 2
y is 0, z is 1. So y!=z is true(1)
24th May 2020, 5:26 PM
Win Htay 🇲🇲
Win Htay 🇲🇲 - avatar