BooleanBoolean

Boolean (bool) is a data type that can take one of two values: true or false.
Syntax:

They are mostly used in comparison operators. Those operators (==, !=, <, >, >=, <=) return bool.

Note

cout prints booleans as numbers, 1 if the boolean is true, and 0 if the boolean is false.

cpp

main.cpp

You can also flip the value of a boolean using the ! operator:

cpp

main.cpp

And most frequently, they are used as conditions in if/while/... statements.

cpp

main.cpp

The size of a bool in C++ is 1 byte.
Yes, it would fit in 1 bit of memory, but you can't store a variable of size less than 1 byte (8 bit) in C++

question-icon

Choose the INCORRECT statement

Select the correct answer

Everything was clear?

Section 3. Chapter 1