1.数组指针
A (*ga)[n] = new A[m][n];
...
delete []ga;
2.二级指针
A** ga = new A*[m];
for(int i = 0; i < m; i++)
ga[i] = new A[n];
...
for(int i = 0; i < m; i++)
delete []ga[i];
delete []ga;
3.//用一维数组来模拟
A* ga = new A[m*n];
...
delete []ga;
对应的用malloc 和free 函数进行操作的方法是:
1.
int (*p)[4] = (int *[])malloc(sizeof(int) *n * m);
free(p);
2.
int **p;
for(int i = 0; i < n; i ++)
{
p[i] = (int *)malloc(sizeof(int) * m);
}
for(int i = 0; i < n; i ++)
free(p[i]);
free(p);
3.
int *p = (int *) malloc(sizeof(int) * n *m);
free(p);
1.数组指针 A (*ga)[n] = new A[m][n]; ... delete []ga;2.二级指针 A** ga = new A*[m]; for(int i = 0; i < m; i++) ga[i] = new A[n]; ... for(int i = 0; i < m; i++)