1

Consider the following program:

#include <iostream>
#include <type_traits>

int main(int argc, char* argv[])
{
    std::cout << std::is_same<decltype("hello"), char*>::value << std::endl;
    std::cout << std::is_same<decltype("hello"), const char*>::value << std::endl;
    std::cout << std::is_same<decltype("hello"), char[5]>::value << std::endl;
    std::cout << std::is_same<decltype("hello"), const char[5]>::value << std::endl;
    std::cout << std::is_same<decltype("hello"), char[6]>::value << std::endl;
    std::cout << std::is_same<decltype("hello"), const char[6]>::value << std::endl;
    std::cout << std::is_same<decltype("hello"), char[]>::value << std::endl;
    std::cout << std::is_same<decltype("hello"), const char[]>::value << std::endl;
    return 0;
}

It returns only zeroes, while I would have expected "hello" to be a const char[6]. What is the type of "hello"?

Vincent
  • 57,703
  • 61
  • 205
  • 388

2 Answers2

3

Edit: I was too quick and didn't notice the const char[6]. Since none of your checks involve &:

Quoting 8.4.1 Literals:

A literal is a primary expression. Its type depends on its form. A string literal is an lvalue; all other literals are prvalues.

Hence, the type is const char (&)[6].

Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49
  • It's type **is** `const char[6]`, the reference is the effect of `decltype`. Please check my duplicate link in question comment. – llllllllll Feb 13 '18 at 22:47
1

Type is const char (&)[6] as you can see here

Jarod42
  • 203,559
  • 14
  • 181
  • 302