#include<iostream>
using namespace std;void testArray() {
//二维数组动态创建和释放
double** p = new double* [13];//13行
for (int i = 0; i < 13; i++) {
for (int j = 0; j < 11; j++) {//11列
//p[i] = new double[11]();//初始化为0
p[i] = new double[11]{ 1,2,3,4,5,6,7,8,9,10,11 }; //初始化列
}
}
for (int i = 0; i < 13; i++) {
for (int j = 0; j < 11; j++) {
//*(*(p + i) + j) = 1;
cout << *(*(p + i) + j) << "\t";//这么写等同于p[i][j],不过这种写法性能更好
}
cout << endl;
}
//释放堆区数据
for (int i = 0; i < 13; i++) {
delete[] p[i];
}
delete[] p;
p = NULL;
}
int main() {
testArray();
return 0;
}
c++二维数组动态创建和删除
最新推荐文章于 2022-09-30 14:46:57 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)