top of page
Frequently Asked C Language Interview Question & Answers
What is the difference between calloc() and malloc()?
A block of memory may be allocated using the function malloc (). The malloc function reserves a block of memory of specified size and returns a pointer of type void(). This means we can assign the base address of the block to any type of pointer
Syntax – P = (cast type*)malloc(byte size);
Calloc() is also a memory allocation function which is generally used to allocate memory for array and structure. malloc() is used to allocate a single block of storage space, calloc() allocates multiple blocks of storage, each of the same size and initializes them with zero.
Syntax – P = (cast type*)calloc(n,array size);
bottom of page