I have a very basic but haunting problem about pointer and array:
int main() {
int a[5] = { 1,2,3,4,5 };
int(*pa)[5] = &a;
std::cout << a << std::endl;
std::cout << &a << std::endl;
std::cout << pa << std::endl;
std::cout << (*pa) << std::endl;
return 0;
}
Surprisingly, all four outputs give the same address, something like '006AF784', which means a == &a and pa == *pa. This does not make any sense to me!
I understand of course 'a' is the pointer to the first element while '&a' is the pointer to the whole array, so 'a+1' is different from '&a+1'. But a variable is equal to its address and a pointer is equal to the content which points to is not understandable to me. I wonder what is exactly going on within C and compiler.