Loading lessons...
Boolean Values
Boolean Values
A boolean is a value that is either true or false. C++ calls the type bool, named after George Boole.
Declaring a boolean
bool isCodingFun = true;
bool isFishTasty = false;
cout << isCodingFun << endl; // 1
cout << isFishTasty << endl; // 0
Why 1 and 0?
Booleans have their own type, but when printed they show up as numbers: true becomes 1, and false becomes 0. They are really just on/off switches inside the computer.
Boolean keywords
truemeans the switch is on.falsemeans the switch is off.- You write them in lowercase.
- A boolean variable holds exactly one of them.
TL;DR
- Use type
boolfor true/false values. - Write
trueorfalsein lowercase. - Printing a bool shows
1for true and0for false.