What is the difference between \"calloc(...)\" and \"malloc(...)\"?

What is the difference between \"calloc(...)\" and \"malloc(...)\"?

Some important distance between calloc and malloc are given below:
 
malloc:
 
malloc takes only the \"size\" of the memory block to be allocated as input parameter.
malloc allocates memory as a single contiguous block.
if  a single contiguous block cannot be allocated then malloc would fail.

calloc:

calloc takes two parameters: the number of memory blocks and the size of each block of memory
calloc allocates memory which may/may not be contiguous.
all the memory blocks are initialized to 0.
it follows from point 2 that, calloc will not fail if memory can beallocated in non-contiguous blocks when a single contiguous blockcannot be allocated.


By:Vivek Kr. Agarwal
Date:

Some important distance between calloc and malloc are given below:
 
malloc:
 
malloc takes only the \"size\" of the memory block to be allocated as input parameter.
malloc allocates memory as a single contiguous block.
if  a single contiguous block cannot be allocated then malloc would fail.

calloc:

calloc takes two parameters: the number of memory blocks and the size of each block of memory
calloc allocates memory which may/may not be contiguous.
all the memory blocks are initialized to 0.
it follows from point 2 that, calloc will not fail if memory can beallocated in non-contiguous blocks when a single contiguous blockcannot be allocated.


By:vishal dhobale
Date:vishaldhobale@gmail.com

Post Your Answers


User Email:

User Name:
Answers:

Related C SUB Links

C SUB interview questions and answers for experienced and fresher