What happens if the following C++ statement is compiled and executed?

int *ptr = NULL;
delete ptr;

a) The program is not semantically correct
b) The program is compiled and executed successfully
c) The program gives a compile-time error
d) The program compiled successfully but throws an error during run-time

1 thought on “What happens if the following C++ statement is compiled and executed?”

  1. b
    Explanation: The above statement is syntactically and semantically correct as C++ allows the programmer to delete a NULL pointer, therefore, the program is compiled and executed successfully.

Leave a Comment