help with operators | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

help with operators

i get how boolean statements work but in some of the challenges i've seen things like if (1 && 2) { cout << "test"; } and i was wondering what exactly is returned when you compare numbers like that.

21st Nov 2016, 1:46 AM
Ángel Perales
Ángel Perales - avatar
2 Answers
+ 1
In C/C++, and most programming languages, 0 is considered false and every other number is considered true. Consequently, '1 && 2' evaluates to true.
21st Nov 2016, 2:18 AM
Arthur Busser
Arthur Busser - avatar
+ 1
1-true; 0-false; && - logic and. & true if all of the operands is true 1&&1 - true, 1&&0 - false; || - logic or; returns true if one of the operands is true. 1||0 true; 1||1 true
21st Nov 2016, 6:34 AM
Andrei
Andrei - avatar