The Copy Constructor

Medium Object Lifecycle (Constructors & Destructors)
Solve in Playground →

Problem Statement

Create a `Box` class with an integer `size`. Write a parameterized constructor that assigns `size`, and a custom copy constructor that prints ‘Copying [size]’ and assigns the size. Read an integer, instantiate `b1`, and create `b2 = b1`.

Input Format

A single integer.

Output Format

Print the message from the copy constructor.

Constraints

None

Sample Input

10

Sample Output

Copying 10

Explanation

A copy constructor is called when a new object is created as a copy of an existing object.

Starter Code

#include <iostream>

class Box {
public:
    int size;
    // Write parameterized and copy constructors
};

int main() {
    int s;
    if (std::cin >> s) {
        // Instantiate b1 and copy it to b2
    }
    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