Join Regular Classroom : Visit ClassroomTech

Difference between malloc() and calloc() in C

To allocate memory dynamically we use the functions malloc() and calloc() function. These functions on success returns the base address of the array.

Though both malloc() and calloc() are used in C programming language to allocate memory dynamically. Despite of having some similarity there are some difference too between these two statements.

No.CriteriaMallocCalloc
1Full FormThe term malloc stadns for memory allocation.Calloc stands for contiguous allocation.
2Syntax(data_type *)malloc((byte_size)*(number_of_elements))(data_type *)calloc(number_of_elements, element_size);
3Return typeOn success malloc() function returns the base address of the array and every memory location will be initialized to a garbage value.On success calloc() returns base address of the array and every memory location will be initialized to 0.
4Speedmalloc() is faster.It is comparatively slower.


Read in details about malloc() and calloc() in Dynamic Memory Allocation.


Follow Us

You Missed

Also Checkout