C library function - free() The C library function void free(void *ptr) deallocates the memory previously allocated by a call to calloc, malloc, or realloc.
The free() function in C++ deallocates a block of memory previously allocated using calloc, malloc or realloc functions, making it available for further allocations. The free() function does not change the value of the pointer, that is it still points to the same memory location.
free() deallocate the previously allocated space. realloc() Change the size of previously allocated space.
It means that whenever you declare a regular variable of any data type in C, the programming language itself is responsible for deallocating or releasing this memory once your program has been executed successfully.
The term free function in C++ simply refers to non-member functions. Every function that is not a member function is a free function.
struct X {
void f() {} // not a free function
};
void g() {} // free function
int h(int, int) { return 1; } // also a free function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With