Free Dynamic Memory in C

To release the dynamically allocated memory, we can use the free() function in C. The free function takes a pointer as an argument that points to the memory block allocated by the malloc(), calloc(), or realloc() functions and deallocates the memory making it available for reuse.

Syntax of free()

free(ptr);

here,

  • ptr is the pointer that points to the dynamically allocated memory block.

Note: Static memory (i.e. memory allocated on the stack) cannot be deleted by the user.

How to Release Memory in C?

In C programming, releasing memory means deallocating memory that was previously allocated dynamically using functions like malloc(), calloc(), or realloc(). In this article, we will learn how to release memory in C.

Similar Reads

Free Dynamic Memory in C

To release the dynamically allocated memory, we can use the free() function in C. The free function takes a pointer as an argument that points to the memory block allocated by the malloc(), calloc(), or realloc() functions and deallocates the memory making it available for reuse....

C Program to Release Allocated Memory

The following program illustrates how we can release memory in C using free() function:...