Difference between calloc() and malloc()?

by Vijayaprasad 2010-02-16 09:41:31

malloc: malloc create the single block of given size by user
calloc: calloc creates multiple blocks of given size
both return void pointer(void *)so boh requires type casting
malloc: eg:
int *p;
p=(int*)malloc(sizeof(int)*5)
above syntax tells that malloc occupies the 10 bytes memeory and assign the address of first byte to P

calloc: eg:
p=(int*)calloc(5,sizeof(int)*5)
above syntax tells that calloc occupies 5 blocks each of the 10 bytes memeory and assign the address of first byte of first block to P

Tagged in:

891
like
0
dislike
0
mail
flag

You must LOGIN to add comments