首页 > 代码库 > 三维数组的动态申请与释放

三维数组的动态申请与释放

#include <iostream>using namespace std;   void main()   {       int i,j,k;   // p[2][3][4]        int ***p;    p = new int **[2];     for(i=0; i<2; i++)     {         p[i]=new int *[3];         for(j=0; j<3; j++)             p[i][j]=new int[4];     }        //finish creating use p[i][j][k] to access the data       for(i=0; i<2; i++)       {        for(j=0; j<3; j++)           {             for(k=0;k<4;k++)            {                 p[i][j][k]=i+j+k;                cout<<p[i][j][k]<<" ";            }            cout<<endl;        }        cout<<endl;    }        //free the memory       for(i=0; i<2; i++)     {        for(j=0; j<3; j++)         {               delete [] p[i][j];           }       }           for(i=0; i<2; i++)       {               delete [] p[i];       }       delete [] p;      } 

  

三维数组的动态申请与释放