ExamVeda
Login
Home
C plus plus miscellaneous
?

What will be the output of the following C++ code?
#include <cstdlib>
#include <iostream>
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;
}

Answer & Solution
Correct Answer: Option D
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.