A boolean data type is declared with the bool
keyword and can only take the values true
or false
. When the value is returned, true
= 1
and false
= 0
.
Example
bool isCodingFun = true;
bool isFishTasty = false;
cout << isCodingFun; // Outputs 1 (true)
cout << isFishTasty; // Outputs 0 (false)
bool isFishTasty = false;
cout << isCodingFun; // Outputs 1 (true)
cout << isFishTasty; // Outputs 0 (false)
Practice Excercise Practice now