A Boolean represents one of two logical states: false or true. Treating it as an integer creates legal but meaningless operations: incrementing a value does not express toggling, and assigning 42 obscures intent. Prefer the built-in bool type and change states explicitly with negation. section 5.2 section 5.5
Listing 5.9 Simulating Boolean values in an integer
const int TRUE = 1;
const int FALSE = 0;
int main() {
int truth = FALSE;
std::cout << "truth is " << (truth ? "real" : "illusory") << "\n";
++truth; #1
std::cout << "truth is " << (truth ? "real" : "illusory") << "\n";
truth = 42; #2
std::cout << "truth is " << (truth ? "real" : "illusory") << "\n";
return 0;
}
Compare integer-based truth values with the explicit bool form; the listing makes accidental incrementing and arbitrary assignment visible. section 5.5
Use Boolean values in ways that preserve their meaning:
- Declare state with bool truth = false rather than int truth = 0. section 5.5
- Toggle explicitly with truth = !truth; do not increment a Boolean. section 5.2 section 5.5
- Return a predicate's computation directly when it already produces true or false. section 12.4
Make the predicate say exactly what it computes
Instead of storing and assigning a temporary result through an if/else chain, write: bool isEven(int n) { return n % 2 == 0; } This shorter form preserves the same behavior while making the returned Boolean relationship immediately clear. section 12.4










