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! or use
to share this post with others.
Its a very helpful site.Thanks a lot…
Thank u so much…….
thanks so much!
i couldnt find good examples so i was struggling
but with these i understand now
thnks..
finally know what dynamic memory allocation is all about..
very helpful website..
EXCELLENT WEBSITE
Thank you very much.