动态创建二维数组
2017-11-13 15:36
204 查看
利用数组指针
char(*c)[5]; try{c = new char[n][5];} catch(bad_alloc) { cerr<<"Out of Memory"<<endl; exit(1); }
其中
c是一个数组指针,[5]指定的是列数。
利用指针的指针
try { char **x = new char *[numberOfRows]; for(int i=0;i<numberOfRows;i++) x[i] = new char[numberOfColumns]; return true; } catch(bad_alloc) { return false; } //delete //删除行数组空间 for(int i=0;i<numberOfRows;i++) delete [] x[i]; //删除行指针 delete []x; x=NULL;
相关文章推荐
- 动态创建二维数组
- 利用动态内存分配创建一个二维数组
- 根据键盘的输入,创建一个动态二维数组,逐一赋值,输出
- C++ 动态创建二维数组
- C++动态创建二维数组,memset()初始化二维数组
- 动态创建和删除二维数组
- C++ 创建动态二维数组
- c++中try_catch的使用,二维数组动态创建
- 动态创建二维数组
- c语言动态创建二维数组的方法
- c++ 使用new动态的创建指定大小的二维数组
- [指针六]动态创建二维数组
- 动态创建二维数组
- 创建动态二维数组
- 动态创建和释放二维数组
- C++如何动态创建二维数组
- c++动态创建二维数组
- c++ 动态创建二维数组
- 动态创建二维数组
- C++ 二维数组动态创建和内存释放