|
|
|
|
|
|
|
Figure 10-1 displays the simple types that are built into the C++ language. This figure is a portion of the complete diagram of C++ data types that you saw in Figure 2-1. |
|
|
|
|
|
|
|
|
In this figure, one of the typesenumis not actually a single data type in the sense that int and float are data types. Instead, it is a mechanism by which we can define our own simple data types. We look at enum later in the chapter. |
|
|
|
|
|
|
|
|
The integral types char, short, int, and long represent nothing more than integers of different sizes. Similarly, the floating point types float, double, and long double simply refer to floating point numbers of different sizes. What do we mean by sizes? |
|
|
|
|
|
|
|
|
In C++, sizes are measured in multiples of bytes. Recall from Chapter 1 that a byte is usually a group of 8 consecutive bits (1s or 0s) in a computer's memory unit. Nearly all computers use an 8-bit byte but some do not. By definition, the size of a C++ char value is 1 byte. |
|
|
|
|
|
|
|
|
Let's use the notation sizeof(SomeType) to denote the size in bytes of a value of type SomeType. Then, by definition, sizeof(char) = 1. Other than char, the sizes of data objects in C++ are highly machine-dependent. On one machine it might be the case that |
|
|
|
|
|
|
|
|
sizeofchar) = 1, sizeofshort) = 2, sizeofint) = 4, and sizeoflong) = 8 |
|
|
|
|
|
|
|
|
On another machine it might be that |
|
|
|
|
|
|
|
|
sizeofchar) = 1, sizeofshort) = 2, sizeofint) = 2, and sizeoflong) = 4 |
|
|
|
|
|
|
|
|
Figure 10-1
C++ Simple Data Types |
|
|
|
|
|