Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
#include
3.
#include
4.
using namespace std;
5.
class X;
6.
struct Node
7.
{
8.
X* data;
9.
bool filled;
10.
Node() : filled(false) { }
11.
};
12.
class X
13.
{
14.
static Node buffer[];
15.
public:
16.
int number;
17.
enum { size = 3};
18.
void* operator new(size_t sz) throw (const char*)
19.
{
20.
void* p = malloc(sz);
21.
if (sz == 0)
22.
throw "Error: malloc() failed";
23.
cout
Options:
A .  X::operator new(size_t)
B .  Error
C .  Runtime error
D .  None of the mentioned
Answer: Option C

In this program, We are giving a location to two variables in the program, So it is arising an exception.
Output:
$ g++ free3.cpp
$ a.out
X::operator new(size_t)
X::operator new(size_t, 0)
X::operator new(size_t, 1)
X::operator new(size_t, 2)
10000
10001
10002
X::operator new(size_t, 0)
Error: buffer location occupied



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers