Skip to content
Related Articles

Related Articles

C++ | new and delete | Question 5

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 28 Jun, 2021

Is it fine to call delete twice for a pointer?

using namespace std;
int main()
    int *ptr = new int;
    delete ptr;
    delete ptr;
    return 0;

(A) Yes
(B) No

Answer: (B)

Explanation: It is undefined behavior to call delete twice on a pointer.

Anything can happen, the program may crash or produce nothing.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!