4
int main() {
    int arr[3] = { 1,3,5 };
    int * ptr1 = arr;   
    int * ptr2 = &arr; //  warning C4047: reference level between int * and int (*)[3] is different
    return 0;
}

I know 'arr' means pointer that has starting address value of array 'arr'. Also, it is a Immutable pointer value. Then, isn't the idea that '&arr' is a address of pointer 'arr', right?

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
백근우
  • 41
  • 3

1 Answers1

3

Yes, but the type differs.

For an array defined like

int arr[3] = { 1,3,5 };

for most of the cases, arr decays to the pointer to the first element in the array, which has the type int *, in this case. So, for the statement

int * ptr1 = arr;

the LHS and the RHS are of same type.

On the other hand, &arr is a pointer to an array of 3 ints, in other words, it's of type int (*)[3]. By saying

int * ptr2 = &arr; 

You are trying to assign it to a int *. They are not compatible types. Hence the warning.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261