Pure Virtual Functions (= 0)

Medium Virtual Functions & Abstract Classes
Solve in Playground →

Problem Statement

Define an `Instrument` class with a pure virtual function `virtual void sound() = 0;`. Create a `Guitar` class that inherits from it and implements `sound()` to print ‘Strum’. Instantiate `Guitar`, point an `Instrument*` to it, and call `sound()`.

Input Format

None

Output Format

Print the sound.

Constraints

None

Sample Output

Strum

Explanation

A pure virtual function (`= 0`) has no implementation in the base class, forcing derived classes to implement the logic.

Starter Code

#include <iostream>

class Instrument {
public:
    // Define pure virtual function
};

class Guitar : public Instrument {
public:
    // Implement sound()
};

int main() {
    // Setup pointer and execute
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used