The first three types, integral constants, floating point constants,
and character constants, are explained in this subsection.
Enumeration constants are explained in
``Enumerations''.
Integral constants
Integral constants may be:
Decimal:
Digits: ``0-9''.
The first digit may not be ``0'' (zero).
Octal:
Digits: ``0-7''.
The first digit must be ``0'' (zero).
Hexadecimal:
Digits: ``0-9'' plus letters ``a-f'' or ``A-F''.
Letters correspond to decimal values 10-15.
Prefixed by ``0x'' or ``0'' (digit zero).
Suffixes:
All of the above can be suffixed to indicate type, as follows:
--------------------------------------------------
Suffix Type
--------------------------------------------------
u or U unsigned
l or L long
both unsigned long
Floating point constants
Consist of integer part, decimal point, fraction part,
an e or E, an optionally signed integer exponent,
and a type suffix, one of f, F, l, or L.
Each of these elements is optional;
however one of the following must be present
for the constant to be a floating point constant:
A decimal point (preceded or followed by a number).
An e with an exponent.
Any combination of the above.
Examples:
xxx eexpxxx.
.xxx
Type determined by suffix;
f or F indicates float,
l or L indicateslong double,
otherwise type is double.
Character constants
One or more characters enclosed in single quotes, as in `x'.
All character constants have type int.
The value of a character constant is the numeric value of the
character in the ASCII character set.
A multiple-character constant that is not an escape sequence (see below)
has a value derived from the numeric values of each character.
For example, the constant `123' has a value of
Character constants may not contain the character ' or new-line.
To represent these characters, and some others that
may not be contained in the source character set,
the compiler provides the following escape sequences:
If the character following a backslash is not one
of those specified, the compiler issues a warning
and treat the backslash-character sequence as the character itself.
Thus, '\\q' is treated as 'q'.
However, if you represent a character this way,
you run the risk that the character
may be made into an escape sequence in the future,
with unpredictable results.
An explicit new-line character is invalid in a character constant
and causes an error message.
The octal escape consists of one to three octal digits.
The hexadecimal escape consists of one or more hexadecimal digits
Wide characters and multibyte characters
A wide character constant is a character constant
prefixed by the letter L.
A wide character has an external encoding as a
multibyte character and an internal representation
as the integral type wchar_t, defined in stddef.h.
A wide character constant has the integral value for
the multibyte character between single quote characters,
as defined by the locale-dependent mapping function mbtowc.