|
|
|
|
|
|
|
header file defines the constants CHAR_MAX and CHAR_MIN, SHRT_MAX and SHRT_MIN, INT_MAX and INT_MIN, and LONG_MAX and LONG_MIN. The unsigned types have a minimum value of zero and maximum values defined by UCHAR_MAX, USHRT_MAX, UINT_MAX, and ULONG_MAX. To find out the values specific to your computer you could print them out like this: |
|
|
|
|
|
|
|
|
#include <limits.h>
.
.
.
cout < Max. long = < LONG_MAX < endl;
cout < Min. long = < LONG_MIN < endl;
.
.
. |
|
|
|
|
|
|
|
|
In C++, integer constants can be specified in three different number bases: decimal (base-10), octal (base-8), and hexadecimal (base-16). Just as the decimal number system has 10 digits0 through 9the octal system has 8 digits0 through 7. The hexadecimal system has digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F, which correspond to the decimal values 0 through 15. Octal and hexadecimal values are used in system software (compilers, linkers, and operating systems, for example) to refer directly to individual bits in a memory cell and to control hardware devices. These manipulations of low-level objects in a computer are the subject of more advanced study and are outside the scope of this book. |
|
|
|
|
|
|
|
|
The following table shows examples of integer constants in C++. Notice that an L or U (either uppercase or lowercase) can be added to the end of a constant to signify long or unsigned, respectively. |
|
|
|
|
| Constant | Type | Remarks | | 1658 | int | Decimal (base-10) integer. | | 03172 | int | Octal (base-8) integer. Begins with 0 (zero).
Decimal equivalent is 1658. | | 0x67A | int | Hexadecimal (base-16) integer. Begins with 0 (zero), then either x or X. Decimal equivalent is 1658. | | 65535U | unsigned int | Unsigned constants end in U or u. | | 421L | long | Explicit long constant. Ends in L or l. | | 53100 | long | Implicit long constant, assuming the machine's maximum int is, say, 32767. | | 389123487UL | unsigned long | Unsigned long constants end in UL or LU in any combination of uppercase and lowercase letters. |
|
|
|