Can someone explain why assigning an array's memory address to a pointer isn't the same as assigning a 'normal' variable's to a pointer? (int a; int* p = &a;)
I know for a fact that the ampersand in front of the array (&arr) points to its memory address, so why doesn't it work to assign it to a pointer this way?
float* p;
float arr[5];
p = arr; // why is this correct
p = &arr; // and this isn't
Quote from Working Draft, Standard for Programming Language C++:
So
arris the same as&arr[0]in your example, which is a pointer to the first element of the array.Notice that you can also do this however:
and access your elements with: