+ 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

26th Dec 2020, 7:44 AM
Achintya Raj
Achintya Raj - avatar
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!
26th Dec 2020, 7:53 AM
noteve
noteve - avatar
+ 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)
26th Dec 2020, 11:59 AM
noteve
noteve - avatar
+ 2
Thanks
26th Dec 2020, 12:01 PM
Achintya Raj
Achintya Raj - avatar
+ 1
Please specify a relevant language (C) in the thread's tags 👍
26th Dec 2020, 7:53 AM
Ipang
+ 1
Ya but what if we check it from the right side i.e., 20<5 In some compilers they may do this
26th Dec 2020, 11:57 AM
Achintya Raj
Achintya Raj - avatar
+ 1
But I am agreed with your answer and reason
26th Dec 2020, 12:00 PM
Achintya Raj
Achintya Raj - avatar
0
I think it must be compiler dependent
26th Dec 2020, 7:45 AM
Achintya Raj
Achintya Raj - avatar
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.
27th Dec 2020, 1:34 AM
noteve
noteve - avatar