Question: Consider the given Program A and Program B. Answer all the five questions based on these two program. Program A struct actor { char name[32];

 Consider the given Program A and Program B. Answer all thefive questions based on these two program. Program A struct actor {char name[32]; struct actor *next; } *head = NULL; char *get_name() {

char *q; q = (char *) malloc(32); printf("Please enter a name: ");

scanf("%s", q); return q; }; Program B struct actor { char *name;

Consider the given Program A and Program B. Answer all the five questions based on these two program. Program A struct actor { char name[32]; struct actor *next; } *head = NULL; char *get_name() { char *q; q = (char *) malloc(32); printf("Please enter a name: "); scanf("%s", q); return q; }; Program B struct actor { char *name; struct actor *next; } *head = NULL; char *get_name() { char *q; q = (char *) malloc(32); printf("Please enter a name: "); scanf("%s", q); return q; }; int insertion() {struct actor *c; char *n; c = malloc(sizeof(struct actor)); if (c == 0) { printf("out of memory "); return -1;} C->name = get_name(); C->next = head; head = c; return 1 }; int insertion() {struct actor *c; char *n; c= malloc(sizeof(struct actor)); if (c == 0) { printf("out of memory "); return -1;} n = get_name(); strcpy(C->name, n); C->next = head; head = c; return 1 }; Which piece of code has memory leak? Neither Program A nor Program B Both Program A and Program B Program A Program B When you write the deletion function for Program A and Program B, respectively, how many free() calls are required? Select all that apply. One for Program A Two for Program A One for Program B Two for Program B Which piece of memory is leaked? malloc(32) in Program A malloc(32) in Program B char name[32] in Program A char name[32] in Program B Where should the memory be freed? In get_name() function in Program A In get_name() function in Program B In insertion() function in Program A In insertion() function in Program B Where should the actor object linked to c be freed? In get_name() in Program A In insertion() Program in A In main() function In a deletion() function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!