Learn C++ - C++ bool Type

The C++ has added a new type, called bool.

A Boolean variable is one whose value can be either true or false.

You can use the bool type to represent true and false.

The predefined literals true and false represent those values.

bool is_ready = true;

The literals true and false can be converted to type int by promotion, with true converting to 1 and false to 0:

int ans = true;           // ans assigned 1 
int promise = false;      // promise assigned 0 

Any numeric or pointer value can be converted implicitly to a bool value.

Any nonzero value converts to true, whereas a zero value converts to false:

bool start = -100;       // start assigned true 
bool stop = 0;           // stop assigned false