free()
this is used to release memory that is allocated dynamically using previous three functions.
Syntax:
void free(ptr);
Â
where ptr – previously allocated memory
Â
The memory allocated in heap will not be released automatically. Programmer should take the responsibility of release that memory.
//Example
#include<stdio.h>
#include<stdlib.h>
Â
int *input()
{
   int *ptr,i;
   ptr=(int*)malloc(5*sizeof(int));
   printf(“Enter any 5 numbers:”);
   for(i=0;i<5;i++)
   {
       scanf(“%d”,ptr+i);
   }
   return ptr;
}
Â
int main()
{
   int i,sum=0;
   int *ptr=input();
Â
   for(i=0;i<5;i++)
   {
       sum+=*(ptr+i);
Â
   }
   printf(“Sum is: %d”,sum);
   free(ptr);
   ptr=NULL;
}