ProgrammingModerateTCS NQT · Wipro

What does calloc(n, size) guarantee that malloc(n * size) does not?

  1. A. The allocated bytes are all set to zero
  2. B. The allocation is always faster
  3. C. The memory comes from the stack instead of the heap
  4. D. The memory is freed automatically when the function returns

Correct answer: A. The allocated bytes are all set to zero

calloc zero-fills the block; malloc's contents are indeterminate. Both blocks live until free is called, both come from the same allocator, and calloc may be slower because of the zeroing.

More C Programming questions

Exams that ask this topic