Indirect pointer assignment, pointer assignment
# Define _ CRT_SECURE_NO_WARNINGS # include <stdio. h> # include <stdlib. h> # include <string. h>/* three conditions for indirect value assignment: Condition 1: // define a real parameter // define a form parameter. Condition 2: // establish an association: pass the real parameter fetch address to Condition 3: // The parameter indirectly modifies the value of the real parameter * // use the n-level pointer parameter to indirectly modify the n-level pointer (real parameter). * // * Indirect assignment scenario // 1 2 3 these three conditions are written in one function // 12 in one piece 3 separately written in another function ====> Function call // 1 23 and write it in a piece of void main () {char from [128]; char to [128] = {0}; char * p1 = from; char * p2 = to; strcpy (from, "1122233133332 fafdsafas "); while (* p1! = '\ 0') {* p2 = * p1; p2 ++; p1 ++;} printf ("to: % s \ n", );} */int getMem3 (char ** myp1, int * mylen1, char ** myp2, int * mylen2) {int ret = 0; char * tmp1, * tmp2; tmp1 = (char *) malloc (100); strcpy (tmp1, "1234456789"); * mylen1 = strlen (tmp1); // Level 1 pointer * myp1 = tmp1; // indirect value of level 2 pointer tmp2 = (char *) malloc (200); strcpy (tmp2, "abcdefghigklmn"); * mylen2 = strlen (tmp2 ); // Level 1 pointer * myp2 = tmp2; // indirect value assignment of level 2 pointer return ret;} int main () {char * p1 = NULL; char * p2 = NULL; int len1 = 0; int len2 = 0; int ret = getMem3 (& p1, & len1, & p2, & len2 ); if (ret! = 0) {printf ("func getMem3 % d", ret); return ret;} printf ("p1: % s \ n", p1); printf ("p2: % s \ n ", p2); if (p1! = NULL) {free (p1); p1 = NULL;} if (p2! = NULL) {free (p2); p2 = NULL;} system ("pause"); return 0 ;}