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 );

Parameters:

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():


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

	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. You can leave a response, or trackback from your own site. 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:

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

  5. Qasim on March 31st, 2013:

    EXCELLENT WEBSITE
    Thank you very much.

Leave a Reply: