C++ | new and delete | Question 4

What happens when delete is used for a NULL pointer?

filter_none

edit
close

play_arrow

link
brightness_4
code

int *ptr = NULL;
delete ptr; 

chevron_right


(A) Compiler Error
(B) Run-time Crash
(C) No Effect


Answer: (C)

Explanation: Deleting a null pointer has no effect, so it is not necessary to check for a null pointer before calling delete.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.