Order of Execution in Multilevel Inheritance

Medium Single & Multilevel Inheritance
Solve in Playground →

Problem Statement

Create a multilevel chain: `A` -> `B` -> `C`. The constructors should print “A”, “B”, “C”. The destructors should print “~C”, “~B”, “~A”. In `main()`, instantiate `C` inside a local block `{}`.

Input Format

None

Output Format

Print the sequence of constructions and destructions.

Constraints

None

Sample Output

A
B
C
~C
~B
~A

Explanation

Constructors execute from the top-most base class downwards. Destructors execute from the most-derived class upwards.

Starter Code

#include <iostream>

class A {
    // Implement constructor and destructor
};

class B {
    // Inherit A, implement constructor and destructor
};

class C {
    // Inherit B, implement constructor and destructor
};

int main() {
    {
        // Instantiate C
    }
    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