In int (*x)[10]; x is a pointer to an array of 10 ints
So why does this code not compile:
int arr[3] ;
int (*p)[3] =arr;
But this works:
int arr[3];
int (*p)[3] =&arr;
arr is an expression that evaluates to an int* (this is the famous 'arrays decay to pointer' feature).
&arr is an expression that evaluates to a int (*)[3].
Array names 'decay' to pointers to the first element of the array in all expressions except when they are operands to the sizeof or & operators. For those two operations, array names retain their 'arrayness' (C99 6.3.2.1/3 "Lvalues, arrays, and function designators").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With