scope of struct pointers in functions
问题 If i have the following in a function: struct example *A=malloc(sizeof(struct example)); does the node/memory space created where A points to get destroyed after the function ends/leaves? Or does it stay in the heap? 回答1: No. memory allocated by malloc will stay allocated until free 'd. Doing things like this: char * function(void) { char c = 'a'; return &c; } on the other hand, is bad, because this object DOES go out of scope when the function ends. malloc allocates memory on the heap.