calloc (Clear Allocation)
used to allocate multiple blocks of memory dynamically with specified size
Â
Differences between malloc and calloc
- malloc can be called with single argument while calloc is called with two arguments.
- calloc also initialises the memory while allocating.
Â
syntax:
void *calloc(n,size);
where n – number of blocks
size- size of each block
Â
Eg: int *ptr=(int *)calloc(10,sizeof(int));
Â
//Example Program
#include<stdio.h>
Â
void main()
{
   int n,i;
   printf(“Enter number of integer variables you want:”);
   scanf(“%d”,&n);
Â
   int *ptr=(int *)calloc(n,sizeof(int));
Â
   for(i=0;i<n;i++)
   {
       printf(“Enter value %d: “,i+1);
       scanf(“%d”,ptr+i);
   }
Â
   printf(“nnYour Elements are:n”);
   for(i=0;i<n;i++)
   {
       printf(“%d “,*(ptr+i));
   }
}