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 is currently one response 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…

Leave a Reply: