What is the type of a string literal in C++?

c++, string, types

Solution

The type of the string literal `"Hello"` is "array of 6 `const` `char`".

Ordinary string literals and UTF-8 string literals are also referred to as narrow string literals. A narrow string literal has type “array of n `const char`”, where n is the size of the string [...]

It can, however, be converted to a `const char*` by array-to-pointer conversion. Array-to-pointer conversion results in a pointer to the first element of the array.

Problem

For example, what is the type of the string literal "Hello", `const char[6]` or `const char*` ?

Original source

Related problems