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;}
#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->next)</code></pre> <p><span>B. <pre><code class="c-program">free(p1->next);free(p1);</code></pre>
মোঃ আরিফুল ইসলাম
Feb 20, 2025