#include <iostream>
#include <typeinfo>
int main()
{
const char a[] = "hello world";
const char * p = "hello world";
auto x = "hello world";
if (typeid(x) == typeid(a))
std::cout << "It an array!\n";
else if (typeid(x) == typeid(p))
std::cout << "It a pointer!\n"; // this is printed
else
std::cout << "It Superman!\n";
}
Почему x
выводится как указатель, когда строковые литералы являются фактически массивами?
Узкий строковый литерал имеет тип "array of n
const char
" [2.14.5 Строковые литералы [lex.string] §8]