Literal Suffixes


Integral Constants

A simple integral constant always has an intrinsic type which is either int, unsigned int, long or unsigned long. It is not possible to define a constant of type char or short except by using an explicit cast. The type of a constant is determined by a number of factors:

  1. The size of the numeric part of the constant
  2. The presence of any suffixes
  3. Whether the constant is decimal, octal or hexadecimal
  4. The implemented size of an int.

The ISO C Standard (6.1.3.2) specifies rules for various types of constant which state that the type is determined from the first type in a list of types in which the value can be represented. So,

FORMAT OF LITERAL

POSSIBLE TYPES

Unsuffixed decimal int, long, unsigned long
Unsuffixed octal or hexadecimal int, unsigned int, long, unsigned long
Suffixed with u or U unsigned int, unsigned long
Suffixed with l or L long, unsigned long
Suffixed with both u/U and l/L unsigned long


The table below demonstrates how the type of an integer constant varies, depending on its magnitude and suffix. The size of an int is assumed to be either 16 bits or 32 bits as indicated.

Decimal / Hexadecimal
Value

Unsuffixed
Decimal

Unsuffixed
Hex / Oct

Suffixed
with U

Suffixed
with L

Suffixed
with UL

int: 16bits

 

 

 

 

 

32767 / 0x7FFF signed int signed int unsigned int signed long unsigned long
32768 / 0x8000 signed long unsigned int unsigned int signed long unsigned long
65536 / 0x10000 signed long signed long unsigned long signed long unsigned long
2147483647 / 0x7FFFFFFF signed long signed long unsigned long signed long unsigned long
2147483648 / 0x80000000 unsigned long unsigned long unsigned long unsigned long unsigned long

int: 32bits

 

 

 

 

 

32767 / 0x7FFF signed int signed int unsigned int signed long unsigned long
32768 / 0x8000 signed int signed int unsigned int signed long unsigned long
65536 / 0x10000 signed int signed int unsigned int signed long unsigned long
2147483647 / 0x7FFFFFFF signed int signed int unsigned int signed long unsigned long
2147483648 / 0x80000000 unsigned long unsigned int unsigned int unsigned long unsigned long


Floating Constants

The type of a floating constant is determined solely by its suffix:

  1. A floating constant with suffix "F" or "f" is of type float
  2. A floating constant without a suffix is of type double
  3. A floating constant with suffix "L" or "l" is of type long double

Index