Constants
Integral constants
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
-
Hexadecimal floating point constant consists of 0x or 0X
followed by a hexadecimal digit sequence with an optional radix (.(,
followed by a p or P, an optional sign and an exponent.
-
Type determined by suffix;
f
or
F
indicates
float,
l
or
L
indicates
long double,
otherwise type is
double.
Character constants
-
One or more
characters enclosed in single quotes, as in 'x'.
-
All character constants have type
int.
-
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 0x333231 on the 3B2.
On the Intel386 microprocessor
the value is
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 will issue a warning
and treat the backslash-character sequence as the
character itself.
Thus, '\q'
will be 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 will cause 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
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005