What happens when a C++ program contains a syntax error?

Options

  • A. The program always runs successfully
  • B. The compiler reports an error and compilation generally fails
  • C. The compiler automatically corrects every error
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. The compiler reports an error and compilation generally fails

Detailed Explanation

Correct Answer: B — The compiler reports an error and compilation generally fails.

Explanation: Syntax errors violate the language grammar. The compiler normally reports diagnostics and does not successfully compile the affected program.