Tuesday, 20 June 2017

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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...