+ 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.
2 Respostas
+ 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.
+ 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