malloc vs calloc

Arguments




malloc

malloc takes only one argument.


malloc(size in bytes);



calloc

calloc takes two arguments.


calloc(number of elements, size of the element);

Initialization




malloc

malloc doesn't initialize the memory area.

The allocated memory area will have garbage values.

Pictorial Explanation

malloc in c


Animated Tutorial





calloc

calloc initialize the memory area to zero.

Pictorial Explanation

calloc in c


Animated Tutorial


Topics You Might Like