Question
1.
#include
2.
#include
3.
using namespace std;
4.
class X
5.
{
6.
public:
7.
void* operator new(size_t sz) throw (const char*)
8.
{
9.
void* p = malloc(sz);
10.
if (p == 0)
11.
throw "malloc() failed";
12.
return p;
13.
}
14.
void operator delete(void* p)
15.
{
16.
cout
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
class X
5.
{
6.
public:
7.
void* operator new(size_t sz) throw (const char*)
8.
{
9.
void* p = malloc(sz);
10.
if (p == 0)
11.
throw "malloc() failed";
12.
return p;
13.
}
14.
void operator delete(void* p)
15.
{
16.
cout
Answer: Option D
Was this answer helpful ?
The memory value allocated for the program depends on compiler ony.
$ g++ free2.cpp
$ a.out
X :: operator delete(void*)
Freeing 400 bytes
Was this answer helpful ?
More Questions on This Topic :
Question 3.
Which operators are used in the free store?
....
Question 4.
What type of class member is operator new?
....
Submit Solution