原理就不写在这里了,毕竟网上的介绍有很多,代码如下所示:
#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;
}
新闻热点
疑难解答
图片精选