malloc is used for only allocating the memory of any given size and return a void pointer .
for e.g.
void *malloc(size);
p = malloc(4); //syntax of malloc
But malloc only allocates memory it does not initialize the allocated memory. So, for initializing the allocated memory we use calloc. it initialize the allocated memory to zero.
void *calloc(num_of_blocks, size_of_each_block);
And when we require to reallocate the memory of previously allocated memory then we use realloc for reallocating memory.
for e.g.
void *malloc(size);
p = malloc(4); //syntax of malloc
But malloc only allocates memory it does not initialize the allocated memory. So, for initializing the allocated memory we use calloc. it initialize the allocated memory to zero.
void *calloc(num_of_blocks, size_of_each_block);
And when we require to reallocate the memory of previously allocated memory then we use realloc for reallocating memory.
void
*
realloc
(
void
*ptr,
size_t
size);
No comments:
Post a Comment