![]() |
VOOZH | about |
The free() function in C is used to free or deallocate the dynamically allocated memory and helps in reducing memory wastage. The C free() function cannot be used to free the statically allocated memory (e.g., local variables) or memory allocated on the stack. It can only be used to deallocate the heap memory previously allocated using malloc(), calloc() and realloc() functions.
The free() function is defined inside <stdlib.h> header file.
void free(void *ptr);
The following C program illustrates the use of the calloc() function to allocate memory dynamically and free() function to release that memory.
Enter number of Elements: 5 Successfully allocated the memory using calloc(). Calloc Memory Successfully freed.
The following C program illustrates the use of the malloc() function to allocate memory dynamically and free() function to release that memory.
Enter number of Elements: 5 Successfully allocated the memory using malloc(). Malloc Memory Successfully freed.