Objective: allocate a memory segment for storing pointers.
Code:
# Include <stdio. h> # include <stdlib. h> void test (char ** P, char * STR, char * str2) {printf ("P: % P \ n", P ); /* P points to the memory start address allocated by malloc x */printf ("& P: % P \ n", & P ); /* & P is the input parameter P's own address X2 */printf ("* P: % P \ n", * P ); /** P: NULL */* P = STR; printf ("* P: % P \ n", * P ); /** P is the STR address */P ++ at this time;/* offset a pointer type to X + 4 */printf ("P: % P \ n ", p); printf ("& P: % P \ n", & P); * P = str2; printf ("* p + 1: % P \ n ", * P);/** P is the str2 address */} int main () {char * STR = "ABC"; char * str2 = "abcdef "; printf ("str: % P \ n", STR); printf ("str2: % P \ n", str2 ); char ** P = malloc (8 * sizeof (char *); printf ("P: % P \ n", P ); /* P points to the memory start address allocated by malloc x */printf ("& P: % P \ n", & P ); /* & P is the address of the pointer Variable P itself X1 */printf ("* P: % P \ n", * P ); /** P is null at this time */test (P, STR, str2); printf ("P: % P \ n", P); printf ("& P: % P \ n ", & P); printf (" * P: % P \ n ", * P);/* the address of Str */printf (" P: % P \ n ", * (p + 1);/* the address of str2 */
Printf ("P: % P \ n", P [1]);/* the address of str2 at this time, the same as * (p + 1 )*/