linked linked linkedin whatsapp remove
Feedback

Programming Languages

Predict the output?

#include<stdlib.h>

#include<stdio.h>

#include<iostream>


using namespace std;


class Test {

int x;

publi

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;

}

Constructor called

new called

delete called

Destructor called


Constructor called

new called

Destructor called

delete called


 new called

Constructor called

Destructor called

delete called


new called

Constructor called

delete called

Destructor called


Answer:

 new called

Constructor called

Destructor called

delete called



Note: This Question is unanswered, help us to find answer for this one

Related Programming Languages Questions and Answers: