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;
如果你想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;
想要看到更多学习笔记、考试复习资料、面试准备资料?
想要看到IBM工作时期的技术积累和国外初创公司的经验总结?
敬请关注:
[CSDN](https://blog.csdn.net/u013152895)
[简书](https://www.jianshu.com/u/594a3de3852d)
[博客园](https://www.cnblogs.com/vigorz/)
[51Testing](http://www.51testing.com/?15263728)