free
void  free ( void * memblock );
stdlib.h
  cplusplus.com  

Deallocate dynamically allocated memory.
  A block of memory previously allocated by a call to malloc, calloc or realloc is freed.
  The memblock parameter must point a previously allocated memory block. If an invalid pointer is passed to the function the behavior is undefined.
  This function only frees memory allocated from the specified functions. Memory obtained from other methods (like C++'s new operator) should not be freed with this function.

Parameters.

memblock
pointer to the memory block to be freed.

Return Value.
  (none)

Portability.
  Defined in ANSI-C.

Example.

/* free example */
#include <stdio.h>
#include <stdlib.h>

main ()
{
  int * buffer1, * buffer2, * buffer3;
  buffer1 = (int*) malloc (100*sizeof(int));
  buffer2 = (int*) calloc (100,sizeof(int));
  buffer3 = (int*) realloc (buffer2,500*sizeof(int));
  free (buffer1);
  free (buffer3);
  return 0;
}
This program has no output. Just demonstrates some ways to allocate and free dynamic memory.

See also.
  malloc, calloc, realloc


© The C++ Resources Network, 2000