+ 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!?

27th Jul 2017, 11:52 AM
Divam
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--;
27th Jul 2017, 12:06 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 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
27th Jul 2017, 12:46 PM
Jihad Naji
Jihad Naji - avatar
+ 6
@Usopp, It's C++
27th Jul 2017, 12:10 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 6
@Divam, "YES" That would give "4"
27th Jul 2017, 12:31 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 1
@Nomeh Uchenna Gabriel What language is this?
27th Jul 2017, 12:08 PM
God Usopp
God Usopp - avatar
+ 1
@Nomeh Uchenna Gabriel Thanks
27th Jul 2017, 12:10 PM
God Usopp
God Usopp - avatar
+ 1
Means, we can also say that the statement is like this, if(y%z=0)
27th Jul 2017, 12:26 PM
Divam