Dynamic allocation of an integer array with elements initial

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

Solution

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

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site