Literal constants have a type, just like variables. By default, integer literals are of type int. However, certain suffixes may be appended to an integer literal to specify a different integer type:
Suffix Type modifier
u or U unsigned
l or L long
ll or LL long long
f or F float
l or L long double
Unsigned may be combined with any of the other two in any order to form unsigned long or unsigned long long.
In all the cases above, the suffix can be specified using either upper or lowercase letters.
For character types( char
). A different character type can be specified by using one of the following prefixes:
Prefix Character type
u char16_t
U char32_t
L wchar_t
For example:
75 // int
75u // unsigned int
75l // long
75ul // unsigned long
75lu // unsigned long
75ULL // unsigned long long
3.14159L // long double
6.02e23f // float
Note that, unlike type suffixes for integer literals, these prefixes are case sensitive: lowercase for char16_t and uppercase for char32_t and wchar_t.
For string literals, apart from the above u, U, and L, two additional prefixes exist:
Prefix Description
u8 The string literal is encoded in the executable using UTF-8
R The string literal is a raw string
In raw strings, backslashes and single and double quotes are all valid characters; the content of the literal is delimited by an initial R"sequence( and a final )sequence", where sequence is any sequence of characters (including an empty sequence). The content of the string is what lies inside the parenthesis, ignoring the delimiting sequence itself. For example:
R"(string with \backslash)"
R"&%$(string with \backslash)&%$"
Both strings above are equivalent to "string with \backslash". The R prefix can be combined with any other prefixes, such as u, L or u8.