C++ | new and delete | Question 5
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.
Please Login to comment...