-
Which of the following should be used for freeing the memory allocated in the following C code?
#include <stdio.h>
struct p
{
struct p *next;
int n;
};
int main()
{
struct p *ptr1 = (struct ptr*)malloc(sizeof(struct p));
ptr1->n = 1;
ptr1->next = (struct ptr*)malloc(sizeof(struct p));
return 0;
}
-
- free(ptr1);
-
free(ptr1);
free(ptr1->next) -
free(ptr1->next);
free(ptr1); - All of above
- None of these
Correct Option: C
free(ptr1->next);
free(ptr1);