New Generic pointer that can point to any data type
1st Parameter
Pointer to the memory block previously allocated with `malloc`, `calloc`, or `realloc` to be deallocated
Read more about parameters of free in parameters section
The freefunction in C language Frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc or calloc.
The free function deallocates the memory previously allocated by a call to malloc, calloc, or realloc. If ptr is a NULL pointer, no operation is performed. The free function does not return a value. After calling free, the pointer becomes a dangling pointer and should not be used. It's crucial to only free memory that was dynamically allocated and to avoid double-freeing memory.
The freefunction takes 1
parameter:
•
void * `ptr`: Pointer to the memory block previously allocated with `malloc`, `calloc`, or `realloc` to be deallocated
Deallocates the memory block pointed to by `ptr`, which must have been previously allocated by a memory allocation function (`malloc`, `calloc`, or `realloc`). Does nothing if `ptr` is `NULL`.
The free function return value :
This function does not return a value
Output
This example demonstrates the basic usage of `free`. It allocates memory for an array of integers, uses the memory, and then frees it.