二级指针内存分配

 

      int b[2]={2,3};
      int c[2]={4,5};
 
      int **p,**q,**m;
      q=new int*[2];
      q[0]=new int;
      q[1]=new int;
      **q=c[0];
      *(*q+1)=c[1];
      delete q[0];
      delete q[1];
      delete []q;
 
      q=(int**)malloc(sizeof(int*)*2);
      q[0]=(int*)malloc(sizeof(int));
      q[1]=(int*)malloc(sizeof(int));
      **q=b[0];
      *(*q+1)=b[1];
      free(q[0]);
      free(q[1]);
      free(q);
 
       q=(int**)malloc(sizeof(int*));
       q[0]=(int*)malloc(sizeof(int)*2);
       q[0][0]=c[0];
       q[0][1]=c[1];
       free(q[0]);
       free(q);

posted @ 2015-04-11 19:47  hy1hy  阅读(1427)  评论(0编辑  收藏  举报