### 對於二維數組,&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;
}``````