A character literal contains a sequence of characters or escape sequences enclosed in single quotation mark symbols, for example 'c'. A character literal may be prefixed with the letter L, for example L'c'. A character literal without the L prefix is an ordinary character literal or a narrow character literal. A character literal with the L prefix is a wide character literal. An ordinary character literal that contains more than one character or escape sequence (excluding single quotes ('), backslashes (\) or new-line characters) is a multicharacter literal.
Character literals have the following form:
.---------------------. V | >>-+---+--'----+-character-------+-+--'------------------------>< '-L-' '-escape_sequence-'
At least one character or escape sequence must appear in the character literal. The characters can be from the source program character set, excluding the single quotation mark, backslash and new-line symbols. A character literal must appear on a single logical source line.
A character literal has type int.
A character literal that contains only one character has type char,
which is an integral type.
In both C and C++, a wide character literal has type wchar_t, and a multicharacter literal has type int.
The value of a narrow or wide character literal containing a single character
is the numeric representation of the character in the character set used at
run time. The lowest four bytes represent the value of an integer
character literal that contains more than one character. The lowest two
bytes of the lowest multibyte charcacter represent the value of a wide
character literal. For the locale type utf
LOCALETYPE(*LOCALEUTF), the lowest four bytes of the lowest multibyte
character represent the value of the wide character literal.
You can represent the double quotation mark symbol by itself, but you must use the backslash symbol followed by a single quotation mark symbol (\' escape sequence) to represent the single quotation mark symbol.
You can represent the new-line character by the \n new-line escape sequence.
You can represent the backslash character by the \\ backslash escape sequence.
The following are examples of character literals:
'a' '\'' L'0' '('
Related References
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.