Question 54Asked in BPSC TRE 1.0 (2023) Computer Science Class 11-12

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

What will happen if the following C++ statement is compiled and executed? int *ptr = NULL; delete ptr;
  1. AThe program is not semantically correct
  2. BThe program is compiled and executed successfully
  3. CThe program gives a compile-time error
  4. DMore than one of the above
  5. ENone of the above
Show answerHide answer

Correct answer: (B) The program is compiled and executed successfully

Explanation

Deleting a null pointer is a no-op that the C++ standard guarantees to be safe. The code compiles and runs normally.

From BPSC TRE 1.0 (2023) Computer Science Class 11-12 — Previous Year Paper

This is question 54 of BPSC TRE 1.0 (2023) Computer Science Class 11-12 — Previous Year Paper. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.