+ 1
Output question
#include <stdio.h> int main() { int x=10,y=20,z=5,i; i=x<y<z; printf("%d\n", i); return 0; } How the output is 1
8 Respuestas
+ 4
It is because you use int to declare i instead of bool and therefore True becomes 1
- - - - - - - - - - - - - - - -
1 or any value = True
0 = False
10 < 20 < 5
10 < 20 is True or 1
1 < 5
1 < 5 is True or 1
>> 1
- - - - - - - - - - - - - - - -
But it still caused an error for mathematical expression reasons. I hope this helps. Happy Coding!
+ 2
Achintya Raj
Yeah I think in Python it does, but if you want that to happen for every compiler to be sure, just add parentheses. 10 < (20 < 5)
+ 2
Thanks
+ 1
Please specify a relevant language (C) in the thread's tags 👍
+ 1
Ya but what if we check it from the right side i.e., 20<5
In some compilers they may do this
+ 1
But I am agreed with your answer and reason
0
I think it must be compiler dependent
0
Achintya Raj Oh I forgot to say this but I think it is not recommended to use boolean expressions like that. It's still better to use &&(and) and ||(or) operators for cleaner code and to be safe and sure of the expression also.