#include <stdlib.h>#include<string.h>#include<stdio.h>Char**GETMEM51 (intnum) { inti =0; Char**P2 =NULL; P2= (Char**)malloc(sizeof(Char*) *num); if(P2 = =NULL) { returnNULL; } for(i=0; i<num; i++) {P2[i]= (Char*)malloc(sizeof(Char) * -);//Char buf[100];sprintf (P2[i],"%d%d%d", i+1, i+1, i+1); } returnp2;}intGETMEM52 (CharP3,intnum) { inti =0; Char**tmp =NULL; if(P3 = = NULL)//Judge P3 rather than *p3. The memory space that the P3 points to can be null { return-1; } tmp= (Char**)malloc(sizeof(Char*) *num); if(TMP = =NULL) { returnNULL; } for(i=0; i<num; i++) {Tmp[i]= (Char*)malloc(sizeof(Char) * -);//Char buf[100];sprintf (Tmp[i],"%d%d%d", i+1, i+1, i+1); } *P3 =tmp; //1 2 return 0;}voidGetmem52_free (CharP3,intnum) { inti =0; Char**tmp =NULL; if(P3 = =NULL) { return ; } tmp= *P3; for(i=0; i<num; i++) { Free(Tmp[i]); } Free(TMP); *P3 = NULL;//assign a value of an argument to null}voidMain () {inti =0, j =0; Char**P2 =NULL; intnum =5; //P2 = getMem51 (num);getMem52 (&p2, num); for(i=0; i<num; i++) {printf ("%s \ n", P2[i]); } getmem52_free (&p2, num); printf ("hello...\n"); System ("Pause"); return ;}
C Improve _day03_ play to multi-level pointer