c++ 使用new动态的创建指定大小的二维数组
2013-05-17 21:07
357 查看
动态的创建一个由用户输入的N*N大小的数组:
动态的生成一个N*M维数的数组:
// test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "iostream" #include "utility.h" using namespace std; int age=18; int _tmain(int argc, _TCHAR* argv[]) { int a=5; //printf("%d",a); cout<<"please input dim N"<<endl; int N=0; cin>>N; printf("\n"); int** arr=new int* ; for (int i=0;i<N;i++) { // arr[i]=new int ; } int count=0; for (int i=0;i<N;i++) { for (int j=0;j<N;j++) { arr[i][j]=count; count++; } } for (int i=0;i<N;i++) { for (int j=0;j<N;j++) { printf("%4d",arr[i][j]); } printf("\n"); } system("pause"); delete [] arr; return 0; }
动态的生成一个N*M维数的数组:
// test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "iostream" #include "utility.h" using namespace std; int age=18; int _tmain(int argc, _TCHAR* argv[]) { int a=5; //printf("%d",a); cout<<"please input dim 1 N, dim 2 M"<<endl; int N=0; int M=0; cin>>N>>M; printf("\n"); int** arr=new int* ; for (int i=0;i<N;i++) { // arr[i]=new int[M]; } int count=0; for (int i=0;i<N;i++) { for (int j=0;j<M;j++) { arr[i][j]=count; count++; } } for (int i=0;i<N;i++) { for (int j=0;j<M;j++) { printf("%4d",arr[i][j]); } printf("\n"); } system("pause"); delete [] arr; return 0; }
相关文章推荐
- C++中创建、初始化以及删除 以变量为大小的动态二维数组
- C++创建动态空间的未知大小的二维数组、三维数组、多维数组
- 【C++】使用new新建动态二维数组
- C++学习笔记四之使用new来创建动态数组
- c++ primer plus 习题5.7(使用new为结构创建动态数组)
- C++使用new创建动态结构
- 【C++学习笔记】使用new创建动态结构
- c++中try_catch的使用,二维数组动态创建
- Oracle创建用户+创建表空间+指定用户使用表空间+修改表空间大小
- C++中二维数组的动态创建与处理
- C++动态创建二维数组,memset()初始化二维数组
- c++ 创建动态二维数组
- C/C++中动态创建和释放二维数组的两种办法
- 使用windows的fsutil命令创建指定大小及类型的测试文件
- 【C++学习笔记】使用New来创建动态数组
- c++中使用new动态分配存储空间
- C++ 用new 动态创建多维数组
- C++ 动态创建二维数组(转载)
- C++ 使用动态二维数组参数
- C++版一维数组和二维数组的动态创建与释放