character literal - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# character literal

From cppreference.com
< cpp‎ | language

### [edit] Syntax

`'` c-char `'` | (1) |
`u` `'` c-char `'` (since C++11) | (2) |
`U` `'` c-char `'` (since C++11) | (3) |
`L` `'` c-char `'` | (4) |
`'` c-char-sequence `'` | (5) |

where

- c-char is either

  - a character from the basic source character set minus single-quote (`'`), backslash (`\`, or the newline character,
  - escape sequence, as defined in escape sequences
  - universal character name, as defined in escape sequences

- c-char-sequence is a sequence of two or more c-chars.

1) narrow character literal or ordinary character literal, e.g. 'a' or '\n' or '\13'. Such literal has type char and the value equal to the representation of c-char in the execution character set. If c-char is not representable in the execution character set, the literal has type int and implementation-defined value
2) UCS-2 character literal, e.g. u'貓', but not u'🍌' (u'\U0001f34c'). Such literal has type char16_t and the value equal to the value of c-char in Unicode, if it is a part of the basic multilingual plane. If c-char is not part of the BMP, the program is ill-formed.
3) UCS-4 character literal, e.g. U'貓' or U'🍌'. Such literal has type char32_t and the value equal to the value of c-char in Unicode.
4) wide character literal, e.g. L'β' or L'貓. Such literal has type wchar_t and the value equal to the value of c-char in the execution wide character set. If c-char is not representable in the execution character set (e.g. a non-BMP value on Windows where wchar_t is 16-bit), the value of the literal is implementation-defined.
5) Multicharacter literal, e.g. 'AB', has type int and implementation-defined value.

### [edit] Notes

Many implementations of multicharacter literals use the values of each char in the literal to initialize successive bytes of the resulting integer, in big-endian order, e.g. the value of '\1\2\3\4' is 0x1020304

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/language/character_literal&oldid=71236"