ExamVeda
Login
Home
C plus plus miscellaneous
?

What will be the output of the following C++ code?
#include <iostream>
#include <new>
#include <cstdlib>
using namespace std;
const int bsize = 512;
int *pa;
bool allocate = true;
void get_memory() 
{
    cerr << "free store exhausted" << endl;
    delete [] pa;
    allocate = false;
}
void eat_memory(int size) 
{
    int *p = new int[size];
    if (allocate)
        eat_memory(size);
    else
        cerr << "free store addr = " << p << endl;
}
int main()
{
    set_new_handler(get_memory);
    pa = new int[bsize];
    cerr << "free store addr = " << pa << endl;
    eat_memory(bsize);
    return 0;
}

Answer & Solution
Correct Answer: Option C
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.