Thursday 31 January 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...