Which is the correct syntax for declaring a pure virtual function in C++?

Options

  • A. virtual void show();
  • B. virtual void show() = 0;
  • C. void virtual show() == 0;
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. virtual void show() = 0;

Detailed Explanation

Correct Answer: Option B

Explanation:
A pure virtual function is declared by placing = 0 after its function declaration. Example: virtual void show() = 0;. This makes the class abstract if the function remains a pure virtual function in that class.