×

C++ Tutorial

C++ Data types

C++ Operators & Keywords

C++ Conditional Statements

C++ Functions

C++ 'this' Pointer, References

C++ Class & Objects

C++ Constructors & Destructors

C++ Operator overloading

C++ 11 (Advance C++)

C++ Preparation

C++ Header Files & Functionsr

Data Structure with C++

C++ - Miscellaneous

C++ Programs

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:

  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!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.