• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C++ | Operator Overloading | Question 10

Predict the output? CPP
#include<stdlib.h>
#include<stdio.h>
#include<iostream>

using namespace std;

class Test {
    int x;
public:
    void* operator new(size_t size);
    void operator delete(void*);
    Test(int i) {
        x = i;
        cout << \"Constructor called \\n\";
    }
    ~Test() { cout << \"Destructor called \\n\"; }
};


void* Test::operator new(size_t size)
{
    void *storage = malloc(size);
    cout << \"new called \\n\";
    return storage;
}

void Test::operator delete(void *p )
{
    cout<<\"delete called \\n\";
    free(p);
}

int main()
{
    Test *m = new Test(5);
    delete m;
    return 0;
}

(A)

new called
Constructor called
delete called
Destructor called

(B)

new called
Constructor called
Destructor called
delete called

(C)

Constructor called
new called
Destructor called
delete called

(D)

Constructor called
new called
delete called
Destructor called

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments