Related Articles

Difference Between Delete And Free() In C++

Prashant | Sun, 02 Aug, 2020 | 107

Difference between delete and free() in CPP

In this post, we are going to learn about the delete and free() in C++, what are the differences between delete and free()?

Quick introduction about delete and free()

free() function

Basically, it was used in C programming language, to free the run time allocated memory, it is a library function and it can also be used in C++ for the same purpose. free() is declared in stdlib.h header file.



delete operator

delete is an operator in C++ programming language, it is used to free the run time allocated memory.


delete pointer_name;

Differences between delete operator and free() function

Both are used for same purpose, but still they have some differences, the differences are:

  1. delete is an operator whereas free() is a library function.
  2. delete free the allocated memory and calls destructor. But free() de-allocate memory but does not call destructor.
  3. delete is faster than free() because an operator is always faster than a function.

Related Articles

Leave a comment