C++ Programming
FREE STORE MCQs
Total Questions : 10
None.
The operand of delete must be a pointer returned by new.
In this program, The memory will go beyond the limit, So there will be exhaustion in memory.
Output:
$ g++ free4.cpp
$ a.out
free store addr = 0x80a8008
Segmentation fault
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
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
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
The memory value allocated for the program depends on compiler ony.
$ g++ free2.cpp
$ a.out
X :: operator delete(void*)
Freeing 400 bytes
In this program, the behavior of the statement delete[] bp is undefined.
$ g++ a.cpp
a.cpp: In static member function 'static void A::operator delete [](void*, size_t)':
a.cpp:12: warning: deleting 'void*' is undefined
a.cpp: In static member function 'static void B::operator delete [](void*, size_t)':
a.cpp:20: warning: deleting 'void*' is undefined
$ a.out
~A()
~A()
~A()
A :: operator delete[]
Free store is a pool of memory available for you to allocate and deallocate storage for objects
during the execution of your program.
new and delete operators is used to allocate and deallocate the memory for the program.
None.
In this program, We are passing the value to the B, So we are printing B::operator delete.
Output:
$ g++ free.cpp
$ a.out
B::operator delete
Recent Questions
Q. Which State/UT Launched The 'Tourist Village Network' To Pro....
Q. Which Of The Following Transaction Can Be Used To Create T-c....
Q. Organizing Taxonomic Information In Logical Classification I....
Q. Rolling Friction Is Caused By ________
Q. A Stone Is Whirled In A Vertical Circle, The Tension In The ....
Q. In A Tropical Year, The Number Of Sidereal Days, Are
Q. Synonym Of UNIFORMITY
Q. Statement: It Is Estimated That About Twenty Lakh People Wi....
Q. Which Logic Gates Output A 1 If Their Inputs Are 0 And 1?
Q. An Action Potential Is Caused By An Influx Of _____ Ions Int....
Q. Force Exerted By Magnetic Field In Hall Effect Transducers I....
Q. The Factors Which Are To Be Considered While Developing A Go....
Q. Blood Group Which Have No Antigen
Q. Threshold Limit Value Of Copper In The Atmospheric Air Is
Q. When Libya Gave Up Its Nuclear Program?
Q. How Much Amount Has Been Extended By The EXIM Bank As The Li....
Q. A Second Order System Exhibits 100% Overshoot. The Damping R....
Q. Which Are The Special Tags Used For Image Mapping?
Q. Indict
Q. Two Perfectly Elastic Spheres Of Equal Mass Moving In The ....