What int (*ptr)[4] really means and how is it different than *ptr?

后端 未结 7 1654
暖寄归人
暖寄归人 2020-12-07 02:49
int (*p)[4] , *ptr;
int a[4] = {10,20,30,40};
printf(\"%p\\n%p\\n%p\",&a,a,&a[0]);
p = &a ;
//p=a;        gives error

//ptr = &a;   gives error
 ptr         


        
7条回答
  •  独厮守ぢ
    2020-12-07 03:24

    I tried to understand what a, &a, and &a[0] are.

    In C arrays decay to pointers. All of those pointers reference the same memory location (first element of the array). The only difference is the type.

    a and &a[0] have the type of the array elements (in this case int)

    &a is of type pointer to array of elements type (in this case array of 4 integers).

提交回复
热议问题