二维数组建立:
int w,h;
cin>>w>>h;
char *a=new char[h];
for(int i=0;i<h;i++)
a[i]=new char[w];
用完后
for(int i=0;i<m;i++) delete[] p[i];
delete[] p;
三维数组建立
cin>>hight>>row >> col ;
//动态定义三维数组:
int *** p3 ;
p3 = new int**[hight ] ;
for( i = 0 ; i < hight ; i ++ )
p3[i] = new int*[row] ;
for( i = 0 ; i < hight ; i ++ )
for( j = 0 ; j < row ; j ++ )
p3[i][j] = new int[col] ;
//输入三维数组值:
for(i = 0 ; i < hight ; i ++ )
for(j = 0 ; j < row ; j ++ )
for( k = 0 ; k < col ; k ++)
p3[i][j][k] = rand()%10 ;
//输出三维数组:
cout<<"输出三维数组"<<endl;
for(i = 0 ; i < hight ; i ++ )
{
for( j = 0 ; j < row ; j ++ )
{
for( k = 0 ; k < col ; k ++ )
cout<<p3[i][j][k]<<' ' ;
cout<<endl;
}
cout<<endl;
}
//释放三维数组
for( i = 0 ; i < hight ; i ++ )
for( j = 0 ; j < row ; j ++ )
delete []p3[i][j] ;
for( i = 0 ; i < hight ; i ++ )
delete []p3[i] ;
delete []p3 ;
return 0 ;