The type of an integer constant is normally int
, if the value
fits in that type, but here are the complete rules. The type
of an integer constant is the first one in this sequence that can
properly represent the value,
int
unsigned int
long int
unsigned long int
long long int
unsigned long long int
and that isn’t excluded by the following rules.
If the constant has ‘l’ or ‘L’ as a suffix, that excludes the
first two types (those that are not long
).
If the constant has ‘ll’ or ‘LL’ as a suffix, that excludes
first four types (those that are not long long
).
If the constant has ‘u’ or ‘U’ as a suffix, that excludes the signed types.
Otherwise, if the constant is decimal (not binary, octal, or hexadecimal), that excludes the unsigned types.
Here are some examples of the suffixes.
3000000000u // three billion asunsigned int
. 0LL // zero as along long int
. 0403l // 259 as along int
. 2147483648 // This is of typelong long int
. // on typical 32-bit machines, // since it won’t fit in 32 bits as a signed number. 2147483648U // This is of typeunsigned int
, // since it fits in 32 unsigned bits.
Suffixes in integer constants are rarely used. When the precise type is important, it is cleaner to convert explicitly (see Explicit Type Conversion).
See Integer Data Types.