"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > What is the True Nature of the \'L\' Prefix in C++?

What is the True Nature of the \'L\' Prefix in C++?

Published on 2024-11-22
Browse:764

What is the True Nature of the \'L\' Prefix in C  ?

Understanding the Function of the 'L' Prefix in C

The 'L' prefix in C serves a specific purpose: it designates a string literal as a wide character string (wchar_t ) rather than a plain character string (char ). While its functionality is clear, its internal definition raises questions.

Actual Definition of the 'L' Prefix

Contrary to popular belief, the 'L' prefix is an intrinsic part of the C core language, akin to the suffixes used to define various data types. Similar to suffixes, the 'L' prefix modifies the type of a string literal in a specific way:

  • '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 on wchar_t vs. Unicode

It is crucial to note that wchar_t does not equate to Unicode. The rant provided in the article's response emphasizes the distinction between these two concepts.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3