Appendix C. Fundamental Types

Figure C.1 lists C++'s fundamental types. The C++ Standard Document does not provide the exact number of bytes required to store variables of these types in memory. However, the C++ Standard Document does indicate how the memory requirements for fundamental types relate to one another. By order of increasing memory requirements, the signed integer types are signed char, short int, int and long int. This means that a short int must provide at least as much storage as a signed char; an int must provide at least as much storage as a short int; and a long int must provide at least as much storage as an int. Each signed integer type has a corresponding unsigned integer type that has the same memory requirements. Unsigned types cannot represent negative values, but can represent twice as many positive values than their associated signed types. By order of increasing memory requirements, the floating-point types are float, double and long double. Like integer types, a double must provide at least as much storage as a float and a long double must provide at least as much storage as a double.


Figure C.1. C++ fundamental types.

(This item is displayed on page 1232 in the print version)

Integral Types

Floating-Point Types

bool

float

char

double

signed char

long double

unsigned char

 

short int

 

unsigned short int

 

int

 

unsigned int

 

long int

 

unsigned long int

 

wchar_t

 

The exact sizes and ranges of values for the fundamental types are implementation dependent. The header files (for the integral types) and (for the floating-point types) specify the ranges of values supported on your system.

The range of values a type supports depends on the number of bytes that are used to represent that type. For example, consider a system with 4 byte (32 bits) ints. For the signed int type, the nonnegative values are in the range 0 to 2,147,483,647 (231 1). The negative values are in the range 1 to 2,147,483,648 (231). This is a total of 232 possible values. An unsigned int on the same system would use the same number of bits to represent data, but would not represent any negative values. This results in values in the range 0 to 4,294,967,295 (232 1). On the same system, a short int could not use more than 32 bits to represent its data and a long int must use at least 32 bits.

C++ provides the data type bool for variables that can hold only the values TRue and false.

Категории