Why would you expect it to work? You declare p
as char**
,
and you try to assign a char[2][5]
to it. The char[2][5]
will convert implicitly to a char (*)[5]
, but afterwards, you
have a pointer, and no further implicit conversions. (EDIT: except to void*
.)
If you think about it, it should be obvious. If you dereference
a char**
, you get a char*
. And this char*
must reside
somewhere in memory, since you have a pointer to it. So where
is it?
If you want to iterate over the outer array in your example:
char (*p)[5] = a;
std::cout << *p[0] << sdt::endl;
std::cout << *p[1] << sdt::endl;
Note that your expression *(*(a+1)+1)
also supposes that you
have an array of pointers somewhere.
Or you can use the usual solution when working with C style
strings:
char const* const a[] = { "hell", "worl" };
and
char const* const* p = a;
In this case, you do have an array of pointers, which does
implicitly convert to a pointer to a pointer (the first element
of the array).
(Of course, the only time you'll really want to use C style
strings is with const variables with static lifetimes. In
most other cases, std::string
is preferable.)