Question: Given the following structure: struct Data { int n; char* name; int* arr[3]; }; n 33 name 0 0 0 0 0 0 0 0

Given the following structure: struct Data { int n; char* name; int* arr[3]; }; n 33 name 0 0 0 0 0 0 0 0 Oo oo Which of the following code fragments dynamically allocate the memory as shown in the diagram above? 1) struct Data *sptr = malloc(sizeof(struct Data)); if (sptr == NULL) { printf("Unable to allocate memory. "); exit(1); } sptr->n = 33; sptr->name - malloc(12 + sizeof(char)); if (sptr->name == NULL) { printf("Unable to allocate memory. "); exit(1); } for (int i = 0; i arr[i] - calloc(4, sizeof(int)); if (sptr->arr[i] = NULL) { printf("Unable to allocate memory. "); exit(1); } } 2) struct Data *sptr = malloc(sizeof(struct Data); if (sptr == NULL) { printf("Unable to allocate memory. "); exit(1); } sptr->name - malloc(12 * sizeof(char)); if (sptr->name == NULL) { printf("Unable to allocate memory. "); exit(1); } for (int i = 0; i arr[i] - malloc(4 * sizeof(int)); if (sptr->arr[i] -- NULL) { printf("Unable to allocate memory. "); exit(1); for (int j = 0; j arr[i] + j) - 0; } 3) struct Data *sptr = malloc(sizeof(struct Data); if (sptr == NULL) { printf("Unable to allocate memory. "); exit(1); } sptr->n = 33; sptr->name = calloc(12, sizeof(char)); if (sptr->name == NULL) { printf("Unable to allocate memory. "); exit(1); } for (int i = 0; i arr[i] = malloc(2 + sizeof(int)); if (sptr->arr[i] == NULL) { printf("Unable to allocate memory. "); exit(1); for (int j = 0; j arr[i] + 3) = 0; } for (int i = 0; i arr[i] = realloc(sptr->arr[i], 4 + sizeof(int)); if (sptr->arr[i] == NULL) { printf("Unable to allocate memory. "); exit(1); } for (int j = 0; j arr[i] + 3 + 2) = 0; } 1 and 3 2 and 3 1 only 2 only 3 only
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
