0

Why this is true ?

If x=10, y=20, z=5 then why i=x<y<z (is True in C++)

8th Jun 2019, 12:20 PM
Aditya Kumar
Aditya Kumar - avatar
3 Antworten
+ 5
Because in C++, "<" has a left-to-right associativity. 10<20<5 == (10<20)<5 // 10<20 is True == (1) < 5 // This is True == True.
8th Jun 2019, 12:34 PM
Diego
Diego - avatar
+ 3
It's because you can't have multiple comparisons, so it only checks the first one, which is true. To make it false, you should do it like this: i = x < y && y < z;
8th Jun 2019, 12:35 PM
Airree
Airree - avatar
+ 1
Thanks for answering.
8th Jun 2019, 1:09 PM
Aditya Kumar
Aditya Kumar - avatar