咳咳,这个问题我也是看了C Primer Plus才了解到的。以前一直以为二维数组名就是一个二级指针,即指向指针的指针。
其实不然,举个例子:
#include <stdio.h>
intmain()
{
int** p, a[5][4] = {0};
p = a;
return 0;
}
上面的程序是无法通过编译的。错误如下:
error C2440: '=' : cannot convert from 'int [5][4]' to 'int ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
这个也证实了其实a[5][4]的数组名a并非二级指针,以前太想当然了。书中对于a的描述是这样的:a是指向由4个int值构成的数组的指针。
而这样赋值是可行的:
#include <stdio.h>
int main()
{
int * pt;
int ** p, a[5][4] = {0};
pt = a[0];
p = &pt;
return 0;
}
一切需要大家探索!
共进!
转载于:https://blog.51cto.com/zero4eva/1373586