Vidyalelo
C++ Programming · Q642

C++ miscellaneous

Programming · C++ Programming · question 642

Q642

What will be the output of the following C++ code? #include #include using namespace std; class X public: void* operator new(size_t sz) throw (const char*) void* p = malloc(sz); if (p == 0) throw "malloc() failed"; return p; void operator delete(void* p) cout << "X :: operator delete(void*)" << endl; free(p); ; class Y int filler[100]; public: void operator delete(void* p, size_t sz) throw (const char*) cout << "Freeing " << sz << " bytes" << endl; free(p); ; ; int main() X* ptr = new X; delete ptr; Y* yptr = new Y; delete yptr;

A.
X::operator delete(void*)
B.
Freeing 400 bytes
C.
Depends on the compiler
D.
Both X::operator delete(void*) & Depends on the compiler
Answer

Answer: Option D

Solution

Answer: Option D
No explanation is given for this question Let's Discuss on Board