Pointer Input and Output Model
# Define _ CRT_SECURE_NO_WARNINGS # include <stdio. h> # include <stdlib. h> # include <string. h> // pointer for output, memory allocated by the called function √ // pointer for input, memory allocated by the main function // calculate the length of int getNum (char ** myp1, int * mylen1, char ** myp2, int * mylen2) {int ret = 0; char * tmp1 = NULL; char * tmp2 = NULL; tmp1 = (char *) malloc (100); if (tmp1 = NULL) {return-1;} tmp1 = strcpy (tmp1, "abcdefg"); * mylen1 = strlen (tmp1 ); * myp1 = tmp1; // indirectly modify the value of the real parameter p1 tmp2 = (char *) ma Lloc (100); if (tmp2 = NULL) {return-2;} tmp2 = strcpy (tmp2, "11222"); * mylen2 = strlen (tmp2 ); * myp2 = tmp2; // indirectly modify the return ret value of the real parameter p2;} int getNum_Free (char ** myp1) {// if (myp1 = NULL) // {// return; //} // free (* myp1); // release the pointer variable, indicating the memory space. // * myp1 = NULL; // change the real parameter to NULL // or enter char * tmp; tmp = myp1; if (myp1 = NULL) {return-1;} tmp = * myp1; free (tmp); * myp1 = NULL; return 0;} int main () {char * p1 = NULL, * p2 = NULL; int len1 = 0, len2 = 0; int ret = 0; ret = getNum (& p1, & len1, & p2, & len2 ); if (! Ret) {printf ("p1: % s \ n", p1); printf ("p2: % s \ n", p2); getNum_Free (& p1 ); getNum_Free (& p2) ;}else {printf ("func getNum (): % d", ret) ;}system ("pause"); return 0 ;}