Question 7.22

When I call malloc to allocate memory for a local pointer, do I have to explicitly free it?


Yes. Remember that a pointer is different from what it points to. Local variables are deallocated when the function returns, but in the case of a pointer variable, this means that the pointer is deallocated, not what it points to. Memory allocated with malloc always persists until you explicitly free it. In general, for every call to malloc, there should be a corresponding call to free.


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback