Wednesday, 30 November 2016

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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...