In C++, the following code will compile:
int a[5];
int (*b)[5] = &a;
while this won't:
int a[5];
int (*b)[5] = a;
When compiling the second one, g++ gives me an error, saying "cannot convert 'int*' to 'int (*)[5]' in initialization".
However, I thought that a
and &a
are just the same because
std::cout << a << std::endl;
and
std::cout << &a << std::endl;
produce the same result.
Apparently, there is a difference between a
, which is the name of the array variable, and &a
, which is the address of that array. But what exactly is the difference?