What is calloc?
calloc() function is used to dynamically allocate multiple blocks of memory. This is a built-in function that is in the <stdlib.h> header file.
It different from malloc in two ways:
- calloc() needs two arguments instead of just one
syntax:
void *calloc(size_t, size_t size);
Example:
int *ptr=(int *)calloc(10, sizeof(int));
An equivalent malloc call:
int *ptr = (int *)malloc(10*(sizeof(int));
- Memory allocate by calloc is initialized to zero.
Note:- malloc and calloc both return NULL when sufficient memory is not available in the heap.
CLLOC Stands for Clear Allocation
MALLOC stand for Memory Alloction.
