#include<stdio.h>
#include<stdlib.h>
int main()
{
// This pointer will hold the base address of the block created
int* ptr;
int n, i;
// Get the number of elements for the array
printf("Enter number of elements:\n");
scanf("%d",&n); // Get the number of elements for the array
ptr = (int*)calloc(n, sizeof(int)); // Dynamically allocate memory using calloc()
// Check if the memory has been successfully allocated by calloc or not
if (ptr == NULL)
{
printf("Memory not allocated.\n");
exit(0);
}
else
{
// Memory has been successfully allocated
printf("Memory successfully allocated using calloc.\n");
for (i = 0; i < n; ++i)
{
ptr[i] = i + 1; // Set the elements of the array
}
printf("The elements of the array are: ");// Print the elements of the array
for (i = 0; i < n; ++i)
{
printf("%d, ", ptr[i]);
}
}
return 0;
}