10.2. Fundamental Data Types

C++ supports all the fundamental data types found in C. C++ also has the same storage classes as C.

10.2.1. Booleans

C++ has a boolean data type which take values of either true or false. The boolean data type is named bool

In C and also C++, integers are often used as a boolean value. Here the value of zero represents the false and any other value is true. Consider, for example, a simple string copy in C as below. A while statement requires a logical (boolean) expression, yet integer assignment is used here. The loop stops after assignment of the null terminator (0).

while( *p++ = *q++ ) ;

Similarly, the C++ bool data type can be used as an integer which takes values of either one or zero.

bool test = true;
int i = 2 + test;  // i is now 3.
test = test - 1;   // test is now 0, or false.

10.2.2. enum

The enum data type behaves the same as the C enum data type.