Question:

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

Show Hint

The syntax= 0` is called a pure specifier, and it's what distinguishes a pure virtual function from a regular virtual function.
Updated On: Jul 2, 2026
  • void virtual show () = 0
  • void show () virtual
  • virtual void show () = 0
  • pure virtual void show ()
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

A pure virtual function is a virtual function in a C++ base class that has no implementation in the base class. It serves as a placeholder and forces derived classes to provide their own implementation.
A class that contains at least one pure virtual function is called an abstract class, and you cannot create an instance (object) of an abstract class.
The syntax for declaring a pure virtual function is to prepend the function declaration with thevirtual` keyword and append= 0` at the end.
Let's analyze the syntax of the options:
(A)void virtual show () = 0`: Thevirtual` keyword is in the wrong place. It should come before the return type.
(B)void show () virtual`: Thevirtual` keyword is in the wrong place.
(C)virtual void show () = 0`: This is the correct syntax. It starts with thevirtual` keyword, followed by the function signature (return type, name, parameters), and ends with= 0`.
(D)pure virtual void show ()`: The keywordpure` is not part of the syntax; the= 0` is what makes the virtual function pure.
Was this answer helpful?
0
0