Interview Questions

What are the differences between malloc() and calloc()?

C Interview Questions and Answers


(Continued from previous question...)

What are the differences between malloc() and calloc()?

There are 2 differences.
First, is in the number of arguments. malloc() takes a single argument(memory required in bytes), while calloc() needs 2 arguments(number of variables to allocate memory, size in bytes of a single variable).
Secondly, malloc() doesnot initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

(Continued on next question...)

Other Interview Questions