Integer Constants
Integer constants can be represented as ordinary decimal numbers, octal numbers, or hexadecimal numbers:
A decimal constant (base 10) begins with a digit that is not 0; for example: 1024
An octal constant (base 8) begins with a 0; for example: 012
A hexadecimal constant (base 16) begins with the two characters 0x or 0X; for example: 0x7f, 0X7f, 0x7F, 0X7F. The hexadecimal digits A to F are not case-sensitive.
The type of an integer constant, if not explicitly specified, is the first type in the appropriate hierarchy that can represent its value.
For decimal constants, the hierarchy of types is:
int, long, unsigned long, long long(*).
For octal or hexadecimal constants, the hierarchy of types is:
int, unsigned int, long, unsigned long, long long(*), unsigned long long(*).
Thus, integer constants normally have type int.
The type can also be explicitly specified by one of the suffixes
L or l (for
long),
LL
(*) or
ll
(*) (for
long long
(*)), and/or
U or u (for
unsigned). Table 1-6 provides
some examples.
|
Decimal |
Octal |
Hexadecimal |
Type |
15 |
017 |
0xf |
int |
32767 |
077777 |
0x7FFF |
int |
10U |
012U |
0xAU |
unsigned int |
32768U |
0100000U |
0x8000u |
unsigned int |
16L |
020L |
0x10L |
long |
27UL |
033ul |
0x1BUL |
unsigned long |
The macros in Table 1-7 are defined to represent constants of an integer type with a given maximum or minimum width N (e. g., = 8, 16, 32, 64). Each of these macros takes a constant integer as its argument and is replaced ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access