Which of the following should be used for freeing the memory allocated in the following C code?
#include struct p{ struct p *next; int x;};int main(){ struct p *p1 = (struct p*)malloc(sizeof(struct p)); p1->x = 1; p1->next = (struct p*)malloc(sizeof(struct p)); return 0;}

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 x;};int main(){ struct p *p1 = (struct p*)malloc(sizeof(struct p)); p1->x = 1; p1->next = (struct p*)malloc(sizeof(struct p)); return 0;}
Correct Answer [ <p><span>A. <pre><code class="c-program">free(p1);free(p1-&gt;next)</code></pre> <p><span>B. <pre><code class="c-program">free(p1-&gt;next);free(p1);</code></pre>

Related Questions

Comment on the following 2 C programs.
#include  //Program 1int main(){ int a; int b; int c;}#include  //Program 2int main(){ int a; { int b; } { int c; }}