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()?

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.

Here are the examples of Examples of delete and free() in C++.

Comments and Discussions

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.