< previous page page_504 next page >

Page 504
The only guarantee made by the C++ language is that
1 = sizeofchar< sizeofshort< sizeofint< sizeoflong)
and
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.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Range of Values The interval within which values of a numeric type must fall, specified in terms of the largest and smallest allowable values.
Integral Types
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.
Ranges of Values
The following table displays sample ranges of values for the char, short, int, and long data types and their unsigned variations:
Type
Size in Bytes*
Minimum Value*Maximum Value*
char
1
-128127
unsigned char
1
0255
short
2
-32,76832,767
unsigned short
2
065,535
int
2
-32,76832,767
unsigned int
2
065,535
long
4
-2,147,483,6482,147,483,647
unsigned long
4
04,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

 
< previous page page_504 next page >