//WAP to read and display elements of 1D array using Dynamic memory allocation(using calloc() function)
#include<stdio.h>
#include<stdlib.h>
int main( )
{

int *p,n,i;
printf("Enter the number of blocks we want to reserve:") ;
scanf("%d",&n) ;
p=(int*)calloc(n,sizeof(int));//malloc() returns void* so we need to typecast with the specific data type
if(p==NULL)
{
printf("Memory not available\n");
exit(1);
}
else
{
printf("\nMemory allocation successful");
printf ("\nEnter integer values: ") ;
for(i=0;i<n;i++)
{
scanf("%d",p+i);
}
printf("\nEntered values are:");
for(i=0;i<n;i++)
printf("\n%d",*(p+i));
return 0;
}
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: