What happens if a program dereferences a null pointer in C++?

Options

  • A. It always returns zero
  • B. It is guaranteed to compile and execute correctly
  • C. The behavior is undefined
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. The behavior is undefined

Detailed Explanation

Correct Answer: Option C

Explanation: Dereferencing a null pointer has undefined behavior in C++. It may crash the program, but a crash is not guaranteed. This differs from deleting a null pointer, which is safe.