+ 1
Can anyone help me with this code?
int x, y, z; y=6; x=5; z=3; if(y%z) cout<<--x; else cout<<x--; Output is 5. Now I can't understand the if statement!?
7 Answers
+ 10
This Language Is C++
y%z is "0"
IF without a comparison operator automatically becomes a Boolean.
so...
if(y%z) means if "0" is "True" write "4"
else write "5"
And since "0" is "False" the output becomes "5"
try this one to get 4
int x, y, z;
y=6;
x=5;
z=3;
if(y%x)
cout<<--x;
else
cout<<x--;
+ 12
@Divam it's like this if you want to make it more understandable: if(y%z==1)
and if u mean the result of (y%z) you're right it's zero
+ 6
@Usopp, It's C++
+ 6
@Divam, "YES" That would give "4"
+ 1
@Nomeh Uchenna Gabriel
What language is this?
+ 1
@Nomeh Uchenna Gabriel
Thanks
+ 1
Means, we can also say that the statement is like this, if(y%z=0)