Dynamic Object Allocation (new and delete)

Easy Dynamic Memory & Smart Pointers
Solve in Playground →

Problem Statement

Create a `Box` class with a public integer `value`. In `main()`, dynamically allocate a `Box` object on the heap using the `new` keyword, read an integer to set its `value`, print it, and then properly free the memory using `delete`.

Input Format

A single integer.

Output Format

Print 'Value: [val]'.

Constraints

Must use new and delete.

Sample Input

42

Sample Output

Value: 42

Explanation

Dynamic allocation allows objects to be created at runtime on the heap, but manual memory management via `delete` is required to prevent leaks.

Starter Code

#include <iostream>

class Box {
public:
    int value;
};

int main() {
    // Dynamically allocate Box, set value, print, and delete
    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