Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

C++ | new and delete | Question 5

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Is it fine to call delete twice for a pointer?




#include<iostream>
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
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads