description | title | ms.date | helpviewer_keywords | ms.assetid | ||||
---|---|---|---|---|---|---|---|---|
Learn more about: Integer Types |
Integer Types |
07/22/2020 |
|
c8926a5e-0e98-4e37-9b05-ce97961379bd |
Every integer constant is given a type based on its value and the way it's expressed. You can force any integer constant to type long
by appending the letter l
or L
to the end of the constant; you can force it to be type unsigned
by appending u
or U
to the value. The lowercase letter l
can be confused with the digit 1 and should be avoided. Some forms of long
integer constants follow:
/* Long decimal constants */
10L
79L
/* Long octal constants */
012L
0115L
/* Long hexadecimal constants */
0xaL or 0xAL
0X4fL or 0x4FL
/* Unsigned long decimal constant */
776745UL
778866LU
The type you assign to a constant depends on the value the constant represents. A constant's value must be in the range of representable values for its type. A constant's type determines which conversions are performed when the constant is used in an expression or when the minus sign (-
) is applied. This list summarizes the conversion rules for integer constants.
-
The type for a decimal constant without a suffix is either
int
,long int
, orunsigned long int
. The first of these three types in which the constant's value can be represented is the type assigned to the constant. -
The type assigned to octal and hexadecimal constants without suffixes is
int
,unsigned int
,long int
, orunsigned long int
depending on the size of the constant. -
The type assigned to constants with a
u
orU
suffix isunsigned int
orunsigned long int
depending on their size. -
The type assigned to constants with an
l
orL
suffix islong int
orunsigned long int
depending on their size. -
The type assigned to constants with a
u
orU
and anl
orL
suffix isunsigned long int
.