Boolean Operators, Example 1
•
int main
•
{
•
bool x = true, y = false, result = true;
•
•
result = x && y || y;
•
cout << result << endl;
•
return 0;
•
}
0
When you insert a boolean value into the output stream (i.e. when you print it) true is printed as 1 and false is printed as 0.
The and operation occurs first due to precedence
So x && y is false since y is false
False || y is false since y is false
The program prints 0