Freeing Memory with free() function - C Memory

C examples for Memory:free

Introduction

free() function takes a pointer as an argument and frees the memory the pointer refers to.

Demo Code

#include <stdio.h> 
#include <string.h> 
#include <stdlib.h> 
int main()/*ww  w .j  a  v a 2s . co  m*/
{
   char *name;
   name = (char *)malloc(80 * sizeof(char));
   if (name != NULL) {
      printf("\nEnter your name: ");
      gets_s(name,80);
      printf("\nHi %s\n", name);
      free(name); //free memory resources 
   }
}

Result


Related Tutorials