Home »
C++ programming language
Difference between delete and free() in C++
Learn: What are delete and free() in C++ programming language, what are the differences between delete operator and free() in C++?
In this post, we are going to learn about the delete and free() in C++, what are the differences between delete and free()?
What is 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.
Syntax
free(pointer_name);
What is delete operator?
delete is an operator in C++ programming language, it is used to free the run time allocated memory.
Syntax
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:
- delete is an operator whereas free() is a library function.
- delete free the allocated memory and calls destructor. But free() de-allocate memory but does not call destructor.
- delete is faster than free() because an operator is always faster than a function.
Here are the examples of Examples of delete and free() in C++.