Boolean in C++

A boolean data type is defined with the bool keyword. A variable in a boolean data type has the values true or false.

Example

bool b1 = true;
bool b2 = false;

In C++, Boolean values which are equal to true are assigned a value of 1, and values which are equal to false are assigned to 0.

Let see what happens when we print these same boolean variables:


#include <iostream>
using namespace std;

int main()
{
    bool b1 = true;
    bool b2 = false;

    cout << b1 << " , " << b2;
    return 0;
}
Output
1 , 0