why cout<<true&&false; is true in sololearn | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

why cout<<true&&false; is true in sololearn

Go to new CPP code and type cout<<true&&false; it will return 1 while it should return 0

12th Dec 2016, 8:07 AM
Shekhar Bahuguna
Shekhar Bahuguna - avatar
6 Answers
+ 6
because cout first execute true so that the ans is 1. which means true..
12th Dec 2016, 5:57 PM
chandni singh
chandni singh - avatar
+ 4
yep, true Shekhar cout<<false||true; also gives 0 but if u use ()braces this problem won't occur cout<<(false||true); is 1
12th Dec 2016, 8:14 AM
Morpheus
Morpheus - avatar
+ 2
No its supposed to return 1. This is because the first thing the cout function comes across is "true". Therfore it will print 1
12th Dec 2016, 8:11 AM
Eddy
+ 1
Its because the "operator precedence", which should to evaluate first. Sorry my english.
13th Dec 2016, 2:28 PM
Aris Sugiarto
Aris Sugiarto - avatar
0
muy linda
14th Dec 2016, 7:10 PM
banaa
banaa - avatar
- 3
i would say aweaome observation
12th Dec 2016, 9:32 AM
manish rawat
manish rawat - avatar