0

I had forgotten about calloc for the longest time, but I was recently reminded of it. Now i'm curious, what would be the difference between malloc(numElems * elemSize); and calloc(numElems, elemSize); ? If my knowledge of arrays is correct, there shouldn't be any difference in the memory allocated.

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by death_oclock
0

Conceptually, calloc works like this:

void *calloc ( size_t n, size_t size )
{
  void *mem = malloc ( n * size );

  memset ( mem, 0, n * size );

  return mem;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.