|
|
Tutorials

Cpp

|
Topic |
How is free() used in C++?
|
|
Explanation |
|
Free() Function is used to free the memory pointed by the pointer back to the memory
heap. This function should be called on a pointer that was used either with "calloc()" or "malloc()", otherwise
the function will destroy the memory management making a system to crash.
Syntax:
void *free(void *ptr);
Example:
#include <stdlib.h>
#include <stdio.h>
int main ()
{
int * ptr;
ptr = (int*) malloc (80*sizeof(int));
free(ptr);
return(0);
}
|
In the above example the first the memory is allocated using the "malloc()" then using the
free() function the memory is freed.
|
| Note |
C++ is one of the most used programming languages in the world. Also known as "C with Classes".
Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.
|
|
|
|