本文主要是介绍int**a = new int[5][6] 怎么delete,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
int **a = new int[5][6],这个根本编译不过去吧。如果你想new一个二维数组出来,应该这样:
int** a= new int*[5];
for (int i = 0; i < 5; ++i)
{
a[i] = new int[6];
}
delete的时候,反过来就行了:
for (int i = 0; i < 5; ++i)
{
delete[] a[i];
}
delete[] a;
三维数组,与此相同,举例如下:
int*** a= new int**[5];
for (int i = 0; i < 5; ++i)
{
a[i] = new int*[6];
for (int j = 0; j < 6; ++j)
{
a[i][j] = new int[7];
}
}
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 6; ++j)
{
delete[] a[i][j];
}
delete[] a[i];
}
delete[] a;
这篇关于int**a = new int[5][6] 怎么delete的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!