0
Why this is true ?
If x=10, y=20, z=5 then why i=x<y<z (is True in C++)
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.
+ 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;
+ 1
Thanks for answering.