Constants
Constants in the C language include:
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:
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 e exp
xxx.
.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
or 0x313233.
-
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:
Escape sequences
new-line
|
NL (LF)
|
\n
|
audible alert
|
BEL
|
\a
|
horizontal tab
|
HT
|
\t
|
question mark
|
?
|
\?
|
vertical tab
|
VT
|
\v
|
double quote
|
"
|
\"
|
backspace
|
BS
|
\b
|
octal escape
|
ooo
|
\ooo
|
carriage return
|
CR
|
\r
|
hexadecimal escape
|
hh
|
\xhh
|
formfeed
|
FF
|
\f
|
backslash
|
\
|
\\
|
single quote
|
'
|
\'
|
|
|
|
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.
Next topic:
String literals
Previous topic:
Keywords
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003