时间:2021-12-27 11:17:21 | 栏目:C代码 | 点击:次
原理就不写在这里了,毕竟网上的介绍有很多,代码如下所示:
#define N 5
#define M 10
int main(int argc, char **argv)
{
int **p;
int i,j;
p = new int* [N];
for (i = 0; i < N; i++)
p[i] = new int [M];
for (i = 0; i < N; i++)
for (j = 0; j < M; j++)
p[i][j] = i + j;
for (i = 0; i < N; i++)
{
for (j = 0; j < M; j++)
{
cout<<"["<<p[i][j]<<"]"<<" ";
cout<<*(*(p + i) + j)<<" "<<endl;
}
cout<<endl;
}
for (i = 0; i < N; i++)
{
delete [] p[i];
p[i] = NULL;
}
delete [] p;
p = NULL;
return 0;
}