# 关于二维数组、三维数组及多维数组的深度理解及其建立方法（为个人理解，经过实践验证）

``````#include<iostream>
using namespace std;
int main()
{int a[9] = { 1,2,3,4,5,6,7,8,9 };//开辟一个一维数组
int* p[3];                        //开辟一个指针数组
for (int i = 0; i < 3; i++)
p[i] = &a[3 * i];             //为指针数组赋值
for (int i = 0; i < 3; i++)       //验证理论
for (int j=0; j < 3; j++)
cout << p[i][j]<<endl;//p[3][3]型

}``````

p2[2][3][2]型：

``````#include<iostream>
using namespace std;
int main()
{
int a[12] = { 1,2,3,4,5,6,7,8 ,9,10,11,12 };//开辟一个数组空间
int* p1[6];                                 //开辟指针数组
int** p2[2];                                //开辟二维指针数组
for (int i = 0; i < 6; i++)                 //为其赋值
p1[i] = &a[i * 2];
for (int i = 0; i < 2; i++)
p2[i] = &p1[i * 3];
for (int i = 0; i < 2; i++)                 //验证理论
for (int j = 0; j < 3; j++)
for (int n = 0; n < 2; n++)
cout << p2[i][j][n] << endl;    //p2[2][3][2]型
}``````

p2[3][2][2]型：

``````#include<iostream>
using namespace std;
int main()
{
int a[12] = { 1,2,3,4,5,6,7,8 ,9,10,11,12 };//开辟一个数组空间
int* p1[6];                                 //开辟指针数组
int** p2[3];                                //开辟二维指针数组
for (int i = 0; i < 6; i++)                 //为其赋值
p1[i] = &a[i * 2];
for (int i = 0; i < 3; i++)
p2[i] = &p1[i * 2];
for (int i = 0; i < 3; i++)                 //验证理论
for (int j = 0; j < 2; j++)
for (int n = 0; n < 2; n++)
cout << p2[i][j][n] << endl;//p2[3][2][2]型
}``````

THE END