Why is x output as a pointer when string literals are actually arrays?
Due to the conversion of the array to a pointer.
If x should be output as an array, only if the following is allowed:
const char m[] = "ABC"; const char n[sizeof(m)] = m;
In C ++, an attribute cannot be initialized with another array (e.g. above). In such cases, the original array breaks up into a pointer type, and you can do this instead:
const char* n = m;
The rules for type inference with auto similar to the rules for type inference in a function template:
template<typename T> void f(T n); f(m); //T is deduced as const char* f("ABC"); //T is deduced as const char* auto n = m; //n type is inferred as const char* auto n = "ABC"; //n type is inferred as const char*
§7.1.6.4 / 6 refers to the auto qualifier:
The type deduced for the variable d, then deduced A is determined using the rules for deriving the template argument from the function call (14.8.2.1) ...
Nawaz Aug 18 2018-12-18T00: 00Z
source share