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, long int and long 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; a long int must provide at least as much storage as an int; and a long long int must provide at least as much storage as a long 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 approximately twice as many positive values as 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.

Image

Fig. C.1. C++ fundamental types.

The exact sizes and ranges of values for the fundamental types are implementation dependent. The header files <climits> (for the integral types) and <cfloat> (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 bit) 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,647 (–231 – 1). 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. C++11 introduced the types long long int and unsigned long long int—typically for 64-bit integer values (though this is not required by the standard). C++11 also introduced the new character types char16_t and char32_t for representing Unicode characters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset