std::unique_ptr Basics

Medium Dynamic Memory & Smart Pointers
Solve in Playground →

Problem Statement

Create a `Widget` class with a `void show()` printing ‘Showing’ and a destructor printing ‘Widget Destroyed’. Wrap its dynamic allocation using `std::unique_ptr`. Call `show()` using the `->` operator. Notice how the destructor is called without you writing `delete`.

Input Format

None

Output Format

Print the sequence.

Constraints

None

Sample Output

Showing
Widget Destroyed

Explanation

A unique_ptr owns the object exclusively. When the unique_ptr goes out of scope, it automatically destroys the object it points to.

Starter Code

#include <iostream>
#include <memory>

class Widget {
public:
    // Implement show() and destructor
};

int main() {
    // Allocate unique_ptr and call show()
    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