Home »
Code Examples »
C Code Examples
C - Use of free() function using calloc() Code Example
The code for Use of free() function using calloc()
#include <stdio.h>
#include <stdlib.h>
int main() {
int* ptr;
int n = 25;
// Dynamically allocate memory using calloc()
ptr = (int*)calloc(n, sizeof(int));
// Chceck whether memory is allocated or not
if (ptr == NULL) {
printf("Memory not allocated \n");
exit(0);
}
printf("Memory allocation is done.\n");
// Freeing the memory using free() function
free(ptr);
printf("Memory freed.");
return 0;
}
/*
Output:
Memory allocation is done.
Memory freed.
*/
Code by IncludeHelp,
on August 11, 2022 19:57