The output of cout

It’s all about Operator Precedence.

The Overloaded Bitwise Left Shift Operator operator<<(std::basic_ostream) has a higher priority than the Logical AND Operator &&.

#include <iostream>
int main() {
    std::cout << (1 && 0);
    return 0;
}

If you are not 146% sure about the priority of an operator, do not hesitate to use brackets. Most modern IDEs will tell you if you don’t need to use them.

Leave a Comment