-
What is the output of this program?
#include <iostream>
#include <new>
#include <cstdlib>
using namespace std;
const int bsize = 128;
int *ptr1;
bool allocate = true;
void get_memory()
{
cerr << "free store exhausted" << endl;
delete [] ptr1;
allocate = false;
}
void eat_memory(int size)
{
int *ptr2 = new int[size];
if (allocate)
eat_memory(size);
else
cerr << "free store addr = " << ptr2 << endl;
}
int main()
{
set_new_handler(get_memory);
ptr1 = new int[bsize];
cerr << "free store addr = " << ptr1 << endl;
eat_memory(bsize);
return 0;
}
-
- Compilation Error
- Segmentation fault
- Free store addr
- Runtime Error
- None of these
Correct Option: B
In this program, The memory will go beyond the limit, So there will be exhaustion in memory.