71. What will be the output of the following C++ code?
#include <iostream>
#include <exception>
using namespace std;
void terminator()
{
cout << "terminate" << endl;
}
void (*old_terminate)() = set_terminate(terminator);
class Botch
{
public:
class Fruit {};
void f()
{
cout << "one" << endl;
throw Fruit();
}
~Botch()
{
throw 'c';
}
};
int main()
{
try
{
Botch b;
b.f();
}
catch(...)
{
cout << "inside catch(...)" << endl;
}
}
#include <iostream>
#include <exception>
using namespace std;
void terminator()
{
cout << "terminate" << endl;
}
void (*old_terminate)() = set_terminate(terminator);
class Botch
{
public:
class Fruit {};
void f()
{
cout << "one" << endl;
throw Fruit();
}
~Botch()
{
throw 'c';
}
};
int main()
{
try
{
Botch b;
b.f();
}
catch(...)
{
cout << "inside catch(...)" << endl;
}
}72. What is the correct function prototype of () operator overloading?
73. How many types of the constructor are there in C++?
74. How many list sequence containers are provided by STL?
75. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<extent<string[10][20][30], 0>::value;
cout<<extent<string[10][20][30], 1>::value;
cout<<extent<string[10][20][30], 2>::value;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<extent<string[10][20][30], 0>::value;
cout<<extent<string[10][20][30], 1>::value;
cout<<extent<string[10][20][30], 2>::value;
return 0;
}76. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
char* ptr;
unsigned long int Test = sizeof(size_t(0) / 3);
cout << Test << endl;
try
{
ptr = new char[size_t(0) / 3];
delete[ ] ptr;
}
catch (bad_alloc &thebadallocation)
{
cout << thebadallocation.what() << endl;
};
return 0;
}
#include <iostream>
using namespace std;
int main()
{
char* ptr;
unsigned long int Test = sizeof(size_t(0) / 3);
cout << Test << endl;
try
{
ptr = new char[size_t(0) / 3];
delete[ ] ptr;
}
catch (bad_alloc &thebadallocation)
{
cout << thebadallocation.what() << endl;
};
return 0;
}77. What will be the output of the following C++ code?
#include <iostream>
#include <exception>
using namespace std;
void myunexpected ()
{
cout << "unexpected called\n";
throw 0;
}
void myfunction () throw (int)
{
throw 'x';
}
int main ()
{
set_unexpected (myunexpected);
try
{
myfunction();
}
catch (int)
{
cout << "caught int\n";
}
catch (...)
{
cout << "caught other exception\n";
}
return 0;
}
#include <iostream>
#include <exception>
using namespace std;
void myunexpected ()
{
cout << "unexpected called\n";
throw 0;
}
void myfunction () throw (int)
{
throw 'x';
}
int main ()
{
set_unexpected (myunexpected);
try
{
myfunction();
}
catch (int)
{
cout << "caught int\n";
}
catch (...)
{
cout << "caught other exception\n";
}
return 0;
}78. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
char first, second;
cout << "Enter a word: ";
first = cin.get();
cin.sync();
second = cin.get();
cout << first << endl;
cout << second << endl;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
char first, second;
cout << "Enter a word: ";
first = cin.get();
cin.sync();
second = cin.get();
cout << first << endl;
cout << second << endl;
return 0;
}79. What will be the output of the following C++ code?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector;
int * p;
unsigned int i;
p = myvector.get_allocator().allocate(5);
for (i = 0; i < 5; i++)
myvector.get_allocator().construct(&p[i], i);
for (i = 0; i < 5; i++)
cout << ' ' << p[i];
for (i = 0; i < 5; i++)
myvector.get_allocator().destroy(&p[i]);
myvector.get_allocator().deallocate(p, 5);
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector;
int * p;
unsigned int i;
p = myvector.get_allocator().allocate(5);
for (i = 0; i < 5; i++)
myvector.get_allocator().construct(&p[i], i);
for (i = 0; i < 5; i++)
cout << ' ' << p[i];
for (i = 0; i < 5; i++)
myvector.get_allocator().destroy(&p[i]);
myvector.get_allocator().deallocate(p, 5);
return 0;
}80. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
try
{
try
{
throw 20;
}
catch (char n)
{
cout << "Inner Catch\n";
}
}
catch (int x)
{
cout << "Outer Catch\n";
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
try
{
try
{
throw 20;
}
catch (char n)
{
cout << "Inner Catch\n";
}
}
catch (int x)
{
cout << "Outer Catch\n";
}
return 0;
}Read More Section(C plus plus miscellaneous)
Each Section contains maximum 100 MCQs question on C plus plus miscellaneous. To get more questions visit other sections.
- C plus plus miscellaneous - Section 1
- C plus plus miscellaneous - Section 2
- C plus plus miscellaneous - Section 3
- C plus plus miscellaneous - Section 4
- C plus plus miscellaneous - Section 5
- C plus plus miscellaneous - Section 6
- C plus plus miscellaneous - Section 7
- C plus plus miscellaneous - Section 8
- C plus plus miscellaneous - Section 9
- C plus plus miscellaneous - Section 11
