A simple problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

A simple problem

int a=-2,b=-1,c=0; if(a<b<c){ printf("TRUE\n"); }else{ printf("FALSE\n"); } //the end I have no idea why/how the output is FALSE

23rd Mar 2018, 7:49 AM
Akib
Akib - avatar
7 Answers
+ 17
in. if (a<b<c) -2<-1 true so this results in 1 (boolean) 1<0 false so output FALSE
23rd Mar 2018, 8:29 AM
🌛DT🌜
🌛DT🌜 - avatar
+ 17
ok.😉👌
25th Mar 2018, 2:35 PM
Hans Larry Mba Bekale
Hans Larry Mba Bekale - avatar
+ 16
In C/C++ if comparison operators(<, >, ==, !=,<=, >=) applied on integers, strings , etc results in 1 --> true 0 --> false
23rd Mar 2018, 8:38 AM
🌛DT🌜
🌛DT🌜 - avatar
+ 15
@🌛DT🌜 thank yu for yur explanation . so if i have a well understanding, yu mean that (a <b ) has created a boolean value 1 which was compared with the value 0 of c ?
25th Mar 2018, 2:26 PM
Hans Larry Mba Bekale
Hans Larry Mba Bekale - avatar
+ 11
@hans Yes u got the point 👍😉
25th Mar 2018, 2:34 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 3
thank you guys for explaining this, it was in my MCQ 😂😂 no one explained how boolean works with this kind of conditions in class😅😅 You guys are awesome. Thanks again.
25th Mar 2018, 6:14 PM
Akib
Akib - avatar
+ 1
you can mix Boolean with integer values?
23rd Mar 2018, 8:36 AM
Akib
Akib - avatar