bool (C++)

bool is the C++ type that holds one of two values: true or false. Booleans are produced by comparisons and drive if-statements and loops.

C++

Internally true is 1 and false is 0, and any non-zero number is treated as true in a condition. By default, printing a bool with cout shows 1 or 0 rather than the words.

Comparison operators like ==, <, and > all produce a bool result.

Examples

C++

#include <iostream>

int main() {
    bool isOpen = true;
    std::cout << (5 > 3) << " " << isOpen << std::endl;
    return 0;
}

Output:

1 1

Learn it in a lesson

See also

Back to the Dictionary