E D R , A S I H C RSS

이중포인터의 동적할당 예제

void main()

{

     int n=3,m=4;

     int i;



     char **p;

     p=(char **)malloc(n*sizeof(char *));

     for (i=0;i<n;i++) {

          p[i]=(char *)malloc(m*sizeof(char));

     }

     strcpy(p[0],"dog");

     strcpy(p[1],"cow");

     strcpy(p[2],"cat");

     for (i=0;i<n;i++) puts(p[i]);

     for (i=0;i<n;i++) {

          free(p[i]);

     }

     free(p);

}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2016-05-08 13:15:54
Processing time 5.2393 sec