Thursday, January 31, 2019

pointers - C: free memory allocated in c

suppose i have a struct:



typedef struct{
char *ID;
char *name;
float price;
int quantity;
} Generic_Properties;


now if i have used malloc to allocate space in the heap for it and saved the address in a pointer, lets call him p1. now i want to free that specific memory block, is it enough to just declare free(p1):



free(p1);


or do i need to separately free ID and name pointers, because I used malloc to allocated space for the string they're pointing to?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...