The bool
Type
The ANSI/ISO C++ Standard has added a new type (new to C++, that is), called bool
. It’s named in honor of the English mathematician George Boole, who developed a mathematical representation of the laws of logic. In computing, a Boolean variable is one whose value can be either true
or false
. In the past, C++, like C, has not had a Boolean type. Instead, as you’ll see in greater detail in Chapters 5 and 6, C++ interprets nonzero values as true and zero values as false. Now, however, you can use the bool
type to represent true and false, and the predefined literals true
and false
represent those values. That is, you can make statements like the following:
bool is_ready = true;
The literals true
and false
can be converted to type ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.