C Reference function free()

If you have allocated a memory block with the functions malloc(), calloc() or realloc() then you need to free the previously allocated memory.

Usage of free():

void free ( void * ptr );


The parameter is a pointer to a memory block that was allocated with malloc(), calloc() or realloc(). If you pass a null pointer then there will no action occur.

Return value:

No return value by the function free().

Source code example of free():


	int main ()
		int * buffer;

		/*get a initial memory block*/
		buffer = (int*) malloc (10*sizeof(int));

		/*free initial memory block*/
		free (buffer);
		return 0;

This entry was posted in C Reference stdlib.h Functions. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

There are currently 5 responses to “C Reference function free()”

Why not let us know what you think by adding your own comment!

  1. kalyan bagchi on April 22nd, 2011:

    Its a very helpful site.Thanks a lot…

  2. Noor on May 27th, 2012:

    Thank u so much…….

  3. Amy on June 9th, 2012:

    thanks so much!
    i couldnt find good examples so i was struggling
    but with these i understand now

  4. sheena on March 15th, 2013:

    finally know what dynamic memory allocation is all about..
    very helpful website..

  5. Qasim on March 31st, 2013:

    Thank you very much.