c++ new delete 分配二维数组
时间:2010-03-16 来源:@sky
#include <iostream>
using namespace std;
int main(void)
{
int **p;
p = new int*[3];
for (int i = 0; i < 3; i++)
p[i] = new int[4];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++)
p[i][j] = i+j;
}
for (int i = 0; i < 3; i++)
delete []p[i];
delete []p;
return 0;
}
using namespace std;
int main(void)
{
int **p;
p = new int*[3];
for (int i = 0; i < 3; i++)
p[i] = new int[4];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++)
p[i][j] = i+j;
}
for (int i = 0; i < 3; i++)
delete []p[i];
delete []p;
return 0;
}
相关阅读 更多 +