Introduced
#include <stdio.h>
#include <malloc.h>intMainvoid){ int*p;//defines a pointer variable, but does not have a period of initial value; The following two functions are for their FU initial value operationf (&p);//The f function, the pointer variable p is attached with an exact value, so it is the correct operation//g (&p);//g function, although the G function does not have an exact value when it is executed, but the value of the pointer variable after the execution of the G function is not an exact value return 0;}voidFint**q) { *q = (int*) malloc (4);//dynamically allocated memory, the operating system does not automatically release memory for programmers without manually releasing it}voidGint**q) { intR//statically allocated memory, after the function (g) is called, the operating system automatically releases memory (out of the stack)*q = &R;}
//To implement the use of memory across functions, only through the use of dynamic memory methods
Example
#include <stdio.h>#include<malloc.h>structstudent{intSID; intAge ;};structStudent * Createstudent (void);voidShowstudent (structStudent *);intMainvoid){ structStudent *PS; PS=createstudent (); Showstudent (PS); return 0;}voidShowstudent (structStudent *PST) {printf ("%d%d\n", Pst->sid, pst->Age );}structStudent * Createstudent (void) { structStudent * p = (structStudent *) malloc (sizeof(structStudent)); P->sid = About; P->age = the; returnp;}/*Output Result:*/
l2--using memory across functions