Character literals

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.

C only The type of a narrow character literal is int. The type of a wide character literal is wchar_t. The type of a multicharacter literal is int.

C++ only The type of a character literal that contains only one character is char, which is an integral type. The type of a wide character literal is wchar_t. The type of a multicharacter literal is int.

Read syntax diagramSkip visual syntax diagram
Character literal syntax

             .---------------------.      
             V                     |      
>>-+---+--'----+-character-------+-+--'------------------------><
   '-L-'       '-escape_sequence-'        

At least one character or escape sequence must appear in the character literal, and the character literal must appear on a single logical source line.

The characters can be from the source program character set. You can represent the double quotation mark symbol by itself, but to represent the single quotation mark symbol, you must use the backslash symbol followed by a single quotation mark symbol ( \' escape sequence). (See Escape sequences for a list of other characters that are represented by escape characters.)

Outside of the basic source character set, the universal character names for letters and digits are allowed in C++ and at the C99 language level. C++ only In C++, you must compile with the -qlanglvl=ucs option for universal character name support.

The following are examples of character literals:
'a' 
'\'' 
L'0' 
'('