Overloading new and delete Operators

Medium Dynamic Memory & Smart Pointers
Solve in Playground →

Problem Statement

Create a `Tracked` class. Overload its `operator new` to print ‘Allocating’ and return `::operator new(size)`. Overload its `operator delete` to print ‘Deallocating’ and call `::operator delete(p)`. Dynamically allocate and free a `Tracked` object.

Input Format

None

Output Format

Print the sequence of overloaded operations.

Constraints

None

Sample Output

Allocating
Deallocating

Explanation

C++ lets you overload memory allocation operators at the class level, allowing custom memory pooling, tracking, or debugging routines.

Starter Code

#include <iostream>

class Tracked {
public:
    // Overload new and delete here
};

int main() {
    // Allocate and delete Tracked object
    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