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

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.

Leave a Comment