Integer literals are used to provide integral values. Three numerical bases are supported, indicated by prefixes:
Base | Prefix | Example |
---|---|---|
Decimal | None | 5 |
Octal | 0 | 0345 |
Hexadecimal | 0x or 0X | 0x12AB , 0X12AB , 0x12ab , 0x12Ab |
Note that this writing doesn't include any sign, so integer literals are always positive. Something like -1
is treated as an expression that has one integer literal (1
) that is negated with a -
The type of a decimal integer literal is the first data type that can fit the value from int
and long
. Since C99, long long
is also supported for very large literals.
The type of an octal or hexadecimal integer literal is the first data type that can fit the value from int
, unsigned
, long
, and unsigned long
. Since C99, long long
and unsigned long long
are also supported for very large literals.
Using various suffixes, the default type of a literal can be changed.
Suffix | Explanation |
---|---|
L , l | long int |
LL , ll (since C99) | long long int |
U , u | unsigned |
The U and L/LL suffixes can be combined in any order and case. It is an error to duplicate suffixes (e.g. provide two U
suffixes) even if they have different cases.