The L prefix denotes a wide character/string literal; i.e., it is of type wchar_t instead of char. Unicode based programs typically use wide strings, while ANSI/ASCII based programs typically do not.
| L. and marks a wide string literal: 11) A string literal that begins with L , such as L"asdf" , is a wide string literal. A wide string literal has type “array of n const wchar_t ”, where n is the size of the string as defined below; it has static storage duration and is initialized with the given characters.
L is a prefix used for wide strings. Each character uses several bytes (depending on the size of wchar_t ). The encoding used is independent from this prefix.
The wchar_t type is an implementation-defined wide character type. In the Microsoft compiler, it represents a 16-bit wide character used to store Unicode encoded as UTF-16LE, the native character type on Windows operating systems.
The literal prefixes are a part of the core language, much like the suffixes:
'a' // type: char
L'a' // type: wchar_t
"a" // type: char[2]
L"a" // type: wchar_t[2]
U"a" // type: char32_t[2]
1 // type: int
1U // type: unsigned int
0.5 // type: double
0.5f // type: float
0.5L // type: long double
Note that wchar_t
has nothing to do with Unicode. Here is an extended rant of mine on the topic.
It's called an encoding prefix:
string-literal
:
|encoding-prefix
opt
"s-char-sequenceopt
"
|encoding-prefix
opt
Rraw-string
encoding-prefix
:
|u8
|u
|U
|L
and marks a wide string literal:
11) A string literal that begins with
L
, such asL"asdf"
, is a wide string literal. A wide string literal has type “array ofn
const wchar_t
”, where n is the size of the string as defined below; it has static storage duration and is initialized with the given characters.
The meaning of L here is wide character: wchar_t
. String with L is coded in 16bit rather than 8bit, take an example:
"A" = 41
L"A" = 00 41
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With