Course Content
C++ Data Types
3. Other Data Types and Type Convesion
C++ Data Types
Boolean
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 istrue
, and0
if the boolean isfalse
.
main.cpp
You can also flip the value of a boolean using the !
operator:
main.cpp
And most frequently, they are used as conditions in if
/while
/... statements.
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++
Choose the INCORRECT statement
Select the correct answer
Everything was clear?
Section 3. Chapter 1