Next: Floating Constants, Previous: Integer Constants, Up: Constants [Contents][Index]
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 (non-long
).
If the constant has ‘ll’ or ‘LL’ as a suffix, that excludes
first four types (non-long long
).
If the constant has ‘u’ or ‘U’ as a suffix, that excludes the signed types.
Otherwise, if the constant is decimal, 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
.
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 Types.