reference of array

arrays, c++, pointers

Solution

Since `str` is an array, the type of `&str` is a "pointer to array of 12 `const` `char`". The valid declaration would be:

char const (*str4)[12] = &str;

The declaration of `str3` works fine because `str2` is a "pointer to `const` `char`", not an array, initialized using array-to-pointer conversion. The same array-to-pointer conversion does not occur when you take the address of an array, as in the declaration of `str4`.

Problem

I have the following code ``` char str[] = "some string"; // legal char const* str2 = str; // legal char const** str3 = &str2; // legal char const** str4 = &str; // illegal (error: cannot convert 'char (*)[12]' to 'const char (*)[]' in initialization ) ``` Why the last one is not compiled? What is the type of `&str`?

Original source

Related problems