In C++, delete operator should only be used either for the pointers pointing to the memory allocated using new operator or for a NULL pointer, and free() should only be used either for the pointers pointing to the memory allocated using malloc() or for a NULL pointer.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- new vs malloc() and free() vs delete in C++
- How to deallocate memory without using free() in C?
- How does free() know the size of memory to be deallocated?
- Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
- delete() in C++
- "delete this" in C++
- How to delete last element from a map in C++
- C++ | new and delete | Question 3
- C++ | new and delete | Question 2
- C++ | new and delete | Question 1
- C++ | new and delete | Question 4
- C++ | new and delete | Question 5
- Delete elements in C++ STL list
- Overloading New and Delete operator in c++
- How to delete an element from the Set by passing its value in C++