0

question in C programming language

I have encountered a question in C programming language and I was wrong in that question. int x = 10, y = 20, z = 5, i; i = x < y < z; printf("%d\n", i); That code outputs "1" and I can't understand why. May anyone explain me why is i equals 1?

31st Oct 2020, 2:27 PM
Alon Daniel
Alon Daniel - avatar
3 Respuestas
+ 4
When a comparison is true it returns 1. When it's false it returns 0. The first comparison x<y is true, so 1 The second is 1<z which is true and so 1 i = 1
31st Oct 2020, 2:33 PM
Davide
Davide - avatar
+ 3
x<y is true so it returns 1. 1<z is true so it again returns 1.
31st Oct 2020, 2:34 PM
Avinesh
Avinesh - avatar
+ 2
Ok thanks!
31st Oct 2020, 2:34 PM
Alon Daniel
Alon Daniel - avatar