ILE C/C++ Language Reference

Integer Literals

Integer literals can represent decimal, octal, or hexadecimal values. They are numbers that do not have a decimal point or an exponential part. However, an integer literal may have a prefix that specifies its base, or a suffix that specifies its type.

>>-+-decimal_constant-----+--+---------------+-----------------><
   +-octal_constant-------+  +-+-l--+--+---+-+
   '-hexadecimal_constant-'  | +-L--+  +-u-+ |
                             | +-ll-+  '-U-' |
                             | '-LL-'        |
                             '-+-u-+--+----+-'
                               '-U-'  +-l--+
                                      +-L--+
                                      +-ll-+
                                      '-LL-'
 
 

The data type of an integer literal is determined by its form, value, and suffix. The following table lists the integer literals and shows the possible data types. The smallest data type that can represent the constant value is used to store the constant.

Integer Literal Possible Data Types
unsuffixed decimal int, long int, unsigned long int, long long int
unsuffixed octal int, unsigned int, long int, unsigned long int, long long int, unsigned long long int
unsuffixed hexadecimal int, unsigned int, long int, unsigned long int, long long int, unsigned long long int
decimal, octal, or hexadecimal suffixed by u or U unsigned int, unsigned long int, unsigned long long int
decimal suffixed by l or L long int, long long int
octal or hexadecimal suffixed by l or L long int, unsigned long int, long long int, unsigned long long int
decimal, octal, or hexadecimal suffixed by both u or U, and l or L unsigned long int, unsigned long long int
decimal suffixed by ll or LL long long int
octal or hexadecimal suffixed by ll or LL long long int, unsigned long long int
decimal, octal, or hexadecimal suffixed by both u or U, and ll or LL unsigned long long int

A plus (+) or minus (-) symbol can precede an integer literal. The operator is treated as a unary operator rather than as part of the literal.

Related References

Decimal Integer Literals

A decimal integer literal contains any of the digits 0 through 9. The first digit cannot be 0.

                 .--------------.
                 V              |
>>-digit_1_to_9----digit_0_to_9-+------------------------------><
 
 

Integer literals beginning with the digit 0 are interpreted as an octal integer literal rather than as a decimal integer literal.

The following are examples of decimal literals:

485976
-433132211
+20
5

A plus (+) or minus (-) symbol can precede the decimal integer literal. The operator is treated as a unary operator rather than as part of the literal.

Related References

Hexadecimal Integer Literals

A hexadecimal integer literal begins with the 0 digit followed by either an x or X, followed by any combination of the digits 0 through 9 and the letters a through f or A through F. The letters A (or a) through F (or f) represent the values 10 through 15, respectively.

           .------------------.
           V                  |
>>-+-0x-+----+-digit_0_to_f-+-+--------------------------------><
   '-0X-'    '-digit_0_to_F-'
 
 

The following are examples of hexadecimal integer literals:

0x3b24
0XF96
0x21
0x3AA
0X29b
0X4bD

Related References

Octal Integer Literals

An octal integer literal begins with the digit 0 and contains any of the digits 0 through 7.

      .--------------.
      V              |
>>-0----digit_0_to_7-+-----------------------------------------><
 
 

The following are examples of octal integer literals:

0
0125
034673
03245

Related References


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]