Sail E0 Webinar

MCQs

Total Questions : 5
Question 1.

What will not be called when the terminate() is arised in constructor?


  1.    main()
  2.    class
  3.    destructor
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> destructor

None.


Question 2.

What function will be called when we have a uncaught exception?


  1.    catch
  2.    throw
  3.    terminate
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> terminate

If we have an uncaught exception means, compiler will throw the control of program to 

terminate function.


Question 3.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
#include
4.
#include
5.
void Funct()
6.
{
7.
cout
  1.    Integer exception raised.
  2.    Funct() was called by terminate().
  3.    both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> Funct() was called by terminate().

As there is no integer in this program, We are printing Funct() was called by terminate().
Output:
$ g++ uce4.cpp
$ a.out
Funct() was called by terminate().


Question 4.


What is the output of this program?


1.
#include
2.
#include
3.
#include
4.
using namespace std;
5.
void myterminate ()
6.
{
7.
cerr
  1.    terminate handler called
  2.    Aborted
  3.    both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> both a & b

In this program, We are using set_terminate to abort the program.
Output:
$ g++ uce2.cpp
$ a.out
terminate handler called
Aborted


Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class Test1
4.
{
5.
};
6.
class Test2 : public Test1 { };
7.
void Funct();
8.
int main()
9.
{
10.
try
11.
{
12.
Funct();
13.
}
14.
catch (const Test1&)
15.
{
16.
cerr
  1.    Caught an exception
  2.    NULL
  3.    both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> Caught an exception

In this program, We are arising the exception by using the method in the class.
Output:
$ g++ uce3.cpp
$ a.out
Caught a exception


Latest Videos

Latest Test Papers