C Language Literals for numbers, characters and strings Integer literals


Example

Integer literals are used to provide integral values. Three numerical bases are supported, indicated by prefixes:

BasePrefixExample
DecimalNone5
Octal00345
Hexadecimal0x or 0X0x12AB, 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.

SuffixExplanation
L, llong int
LL, ll (since C99)long long int
U, uunsigned

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.