This repository has been archived on 2025-12-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2024-09-20 14:17:13 +03:00

33 lines
574 B
C

// Demonstration of calloc and free
#include <stdio.h>
#include <stdlib.h>
int main () {
int i, n, *a;
printf("Number of elements to be entered:\n");
scanf("%d",&n);
a = (int*)calloc(n, sizeof(int));
if (a == NULL) {
printf("Error! memory not allocated.");
exit(0);
}
printf("Enter %d numbers:\n",n);
for( i=0 ; i < n ; i++ ) {
scanf("%d",&a[i]);
}
printf("The numbers entered are: ");
for( i=0 ; i < n ; i++ ) {
printf("%d ", a[i]);
}
printf("\n");
// free the memory
free(a);
return(0);
}