Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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];

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions