free : free « stdlib.h « C Tutorial






ItemValue
Header filestdlib.h
Declarationvoid free(void *ptr);
Returnreturns the memory to the heap.


#include <stdlib.h>
  #include <stdio.h>

  int main(void)
  {
    char *str[100];
    int i;

    for(i=0; i<100; i++) {
      if((str[i] = malloc(128))==NULL) {
        printf("Allocation Error\n");
        exit(1);
      }
      gets(str[i]);
    }

    /* now free the memory */
    for(i=0; i<100; i++){
        free(str[i]);
    }
    return 0;
  }








23.13.free
23.13.1.free