+ 5

What is the output of this code segment ?

cout<<(3&&4); Please explain how (a&&b) works...

19th Sep 2017, 12:46 PM
Abhishek Tandon
Abhishek Tandon - avatar
2 Respostas
+ 3
The && operator checks whether all of its logical comparisons are true. In this case, you are asking whether 3 AND 4 are true. In C++, any value that is greater than zero is evaluated as true. So, you could write the following: cout << (3 && 5 && 9 && 21 && 2) << endl; //This will output 1 In C++, the value of 'true' is outputted as 1 and 'false' is outputted as 0. cout << (3 && 4 && 0) << endl; //This will output 0.
20th Sep 2017, 1:07 AM
Zeke Williams
Zeke Williams - avatar
+ 6
@Zeke Thanks..! Really a helpful answer
20th Sep 2017, 4:04 AM
Abhishek Tandon
Abhishek Tandon - avatar