free - C stdlib.h

C examples for stdlib.h:free

type

function

From


<cstdlib>
<stdlib.h>

Description

Deallocate memory block

Prototype

void free (void* ptr);

Parameters

Parameter Description
ptr Pointer to a memory block allocated with malloc, calloc or realloc.

Return Value

none

Demo Code


#include <stdlib.h>

int main ()/*  w w  w  .  j a v a 2 s.  co  m*/
{
  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 (buffer2);
  free (buffer3);
  return 0;
}

Related Tutorials