calloc



->calloc() method is used to allocate memory dynamically for array variables.

#include<stdio.h>
#include<stdlib.h>
int *a,*t,n;
void main()
{
printf("Enter the size of array:\n");
scanf("%d",&n);
a=(int *)calloc(n,sizeof(int));
if(a==NULL)
{
 printf("out of memory.!!");
 return;
}
printf("Array elements are:\n");
for(t=a;t<a+n;t++)
{
printf("%d\n",*t);
}
}

No comments:

Post a Comment