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.
Recommended Posts:
- C | Dynamic Memory Allocation | Question 7
- C | Dynamic Memory Allocation | Question 3
- C | Dynamic Memory Allocation | Question 1
- C | Dynamic Memory Allocation | Question 2
- C | Dynamic Memory Allocation | Question 8
- C | Dynamic Memory Allocation | Question 5
- C | Dynamic Memory Allocation | Question 8
- Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
- MCQ on Memory allocation and compilation process
- How to restrict dynamic allocation of objects in C++?
- IPC through shared memory
- Memory leak in C++ and How to avoid it?
- How to deallocate memory without using free() in C?
- Memory Layout of C Programs
- What is Memory Leak? How can we avoid?

