simple example of calloc

//example of using calloc

#include<stdio.h>
#include<conio.h>

void main()
{
int *p;
int n,i;
printf("\nEnter the number of elements : ");
scanf("%d",&n);
p=(int *)calloc(n,sizeof(int));

printf("\nEnter the values : ");
for(i=0;i<n;i++)
scanf("%d",(p+i));

printf("\nValues are :");
for(i=0;i<n;i++)
printf("%d,",*(p+i));

getch();

}





Input / Output :


Enter the number of elements : 6

Enter the values : 12
23
34
45
56
67

Values are :12,23,34,45,56,67,

Comments

Popular posts from this blog

Pascal Triangle using 2D array

JAVA program to add two distance