Robert Smith
Robert Smith

Reputation: 309

Char literal differences?

Been taking some STL c++11 courses and am hung-up on the specifications surrounding char literals.

Given the following char literals, I've been able to identify them as follows:

'a'   // unsigned char
L'a'  // wchar_t
"a"   // ??? char ?
L"a"  // ??? long wchar_t ?

The double quotation marks are the trip up, here. As my lessons have not covered strings yet, the answer that is expected here is a form of char.

What type do "a" and L"a" represent ?

Upvotes: 0

Views: 57

Answers (1)

Matteo Italia
Matteo Italia

Reputation: 126777

Your lessons may have not covered strings yet, but nonetheless the values with the double quotation marks are string literals (the first narrow, the second wide); their types are respectively const char[2] and const wchar_t[2].

Incidentally, many people often say that they are const char * and const wchar_t *, but it's incorrect - as all arrays they easily decay to a pointer to their first element, but they are arrays indeed, as you can check using e.g. sizeof.

Upvotes: 3

Related Questions