Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dynamic allocation of an integer array (with elements initialized to 0) of size

ID: 3923586 • Letter: D

Question

Dynamic allocation of an integer array (with elements initialized to 0) of size 3 can be done safely using: int 'pointer = malloc(sizeof(int)*3); pointer[0] = 0; pointer[1] = 0; pointer[2] = 0; int 'pointer = calloc(3, sizeof(int)); if (pointer == NULL){printf("Unable to allocate memory. "); exit(1);} int 'pointer = calloc(1, sizeof(int)); if (pointer == NULL){printf("Unable to allocate memory. "); exit(1);} pointer = realloc(pointer, 3*sizeof(int)); if (pointer == NULL){printf("Unable to allocate memory. "); exit(1);} Select one choice: A, B and C A and B A only B and C B only

Explanation / Answer

We can use both malloc and calloc to allocate memory dynamically.

malloc allocate memory with garbage value
but calloc allocate memory and initialize with 0

So, Ans: A and B