数组名并不是指针,两者是不同的,把数组名称为指针是最常见的错误之一。
int *p=a;这样写之所以是错误的,原因是与a相对应的pointer type是int(*)[4],而p的类型是int*,类型不相容,不能这样赋值。a如果这样定义:
int arr[6],跟a相对应的pointer type是int*,这时候就可以p=arr;
注意:
别把我上面说的“与a相对应的pointer type”理解成a的类型是pointer type,NO!
a的类型是array type,int a[4][4],根据C标准规定的conversion of array type to pointer type规则,一个表达式中的数组名除了作为sizeof和&的操作数的情况外,会产生一个地址,同时这个地址的类型会由a的array type转换为pointer type,“相对应的pointer type”指的这个pointer type,不是a的类型。