First give an example
#include <stdio.h> #include <stdlib.h> typedef struct { int Data [the MaxSize]; // save the element stack int Top; // stack pointer } SqStack; // initialize stack void InitStack (SqStack * ST) { ST = (SqStack *) the malloc ( the sizeof (SqStack)); ST -> Top = 0 ; the printf ( " initialization stack complete \ n- " ); } int main () { SqStack * St; InitStack (St); printf ( "%d",st->top); }
This is a stack of the initialization sequence, but the run will find the last printf statement did not execute, even if we will stack pointer as a parameter passed to St initialization function, the initialization function of its allocated space, but due to re-address malloc carried out the assignment, operation after operation so it is not the original parameters.