C | Dynamic Memory Allocation | Question 6

Which of the following is true?
(A) “ptr = calloc(m, n)” is equivalent to following
ptr = malloc(m * n);

(B) “ptr = calloc(m, n)” is equivalent to following
ptr = malloc(m * n);
memset(ptr, 0, m * n);

(C) “ptr = calloc(m, n)” is equivalent to following
ptr = malloc(m);
memset(ptr, 0, m);

(D) “ptr = calloc(m, n)” is equivalent to following
ptr = malloc(n);
memset(ptr, 0, n);



Answer: (B)

Explanation: See calloc() versus malloc() for details.


Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up