|
|
|
|
|
|
|
The only guarantee made by the C++ language is that |
|
|
|
|
|
|
|
|
1 = sizeofchar) < sizeofshort) < sizeofint) < sizeoflong) |
|
|
|
|
|
|
|
|
sizeoffloat) < sizeofdouble) < sizeoflong double) |
|
|
|
|
|
|
|
|
For numeric data, the size of a data object determines its range of values. Let's look in more detail at the sizes, ranges of values, and constants for each of the built-in types. |
|
|
|
 |
|
 |
|
|
Range of Values The interval within which values of a numeric type must fall, specified in terms of the largest and smallest allowable values. |
|
|
|
|
|
|
|
|
Before looking at how the sizes of integral types affect their possible values, we remind you that the reserved word unsigned may precede the name of an integral typeunsigned char, unsigned short, unsigned int, unsigned long. Values of these types are nonnegative integers with values from 0 through some machine-dependent maximum value. Although we rarely use unsigned types in this book, we include them in this discussion for thoroughness. |
|
|
|
|
|
|
|
|
The following table displays sample ranges of values for the char, short, int, and long data types and their unsigned variations: |
|
|
|
|
| Type | | Minimum Value* | Maximum Value* | | char | | -128 | 127 | | unsigned char | | 0 | 255 | | short | | -32,768 | 32,767 | | unsigned short | | 0 | 65,535 | | int | | -32,768 | 32,767 | | unsigned int | | 0 | 65,535 | | long | | -2,147,483,648 | 2,147,483,647 | | unsigned long | | 0 | 4,294,967,295 | | * These values are for one particular machine. Your machine's values may be different. |
|
|
|
|
|
|
Most C++ environments provide the header file limits.h, from which you can determine the maximum and minimum values for your machine. This |
|
|
|
|
|