Why does this expression not work

An int (*x)[10]; xarray pointer of 10 ints

So why this code does not compile:

int arr[3] ;

int (*p)[3] =arr;

But it works:

int  arr[3];

int (*p)[3] =&arr;
+5
source share
2 answers

arris an expression that evaluates to int*(this is the well-known function "decay an array into a pointer").

&arr- An expression that evaluates to int (*)[3].

Array names "decay" points to the first element of the array in all expressions, except when they are operands for sizeofor &. For these two operations, array names retain their "massiveness" (C99 6.3.2.1/3 "Lvalues, arrays and function notation").

+10

, :

int i;
int* pi = i; // error: no conversion from int to int*
0

All Articles