### 对于二维数组,&a与&a[0]与a一样吗？

``````int a[2][2] = { 1,2,3,4 };
auto g = &a;
auto p = &a[0];
auto q = a[0];
cout << g << endl; cout << p << endl; cout << q << endl;``````

``````++q;
++p;
++g;
cout << g << endl;
cout<< p << endl;
cout << q << endl;``````

008FFEA8
008FFEA0
008FFE9C

``````    int (*g)[2][2]= &a;
int (*p)[2]= &a[0];
int *q = a[0];``````

g是指向整个二维数组的指针，p是指向二维数组中整个a[0]的指针，q是指向a[0][0]的指针；当他们各自自加1时：g指向下一个相邻的下一个二位数组，p指向a[1]，q指向a[0][1]；此时g指向的东西是未知的，所以这时候输出什么都不奇怪，我们来看看这时输出g指向的二维数组的元素是什么吧：

``````for (int i = 0; i < 4; ++i) {
cout << (*(*g)+i) <<" "<< *(*(*g)+i)<<endl;
}``````

``````#include<iostream>
using namespace std;
int main() {
int a[2][2] = { 1,2,3,4 };
int (*g) [2][2]= &a;
int (*p)[2]= &a[0];
int *q = a[0];

cout << g << endl;
cout << p << endl;
cout << q << endl;
++q;
++p;
++g;
cout << g << endl;
cout<< p << endl;
cout << q << endl;

cout << endl;
for (int i = 0; i < 4; ++i) {
cout << (*(*g)+i) <<" "<< *(*(*g)+i)<<endl;
}
system("pause");
return 0;
}
``````

//更新

``````#include<iostream>
using namespace std;
int main() {
int a[2][2] = { 1,2,3,4 };
int(*g)[2][2] = &a;
int(*p)[2] = &a[0];
int *q = a[0];

cout << typeid(g).name() << endl;
cout << typeid(p).name() << endl;
cout << typeid(q).name() << endl;

system("pause");
return 0;
}``````