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