Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

When exceptions are used?


  1.    To preserve the program
  2.    Exceptions are used when postconditions of a function cannot be satisfied.
  3.    Exceptions are used when postconditions of a function can be satisfied.
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> Exceptions are used when postconditions of a function can be satisfied.

None.


Question 2.

Pick out the correct Answer.


  1.    Exceptions are not suitable for critical points in code.
  2.    Exception are suitable for critical points in code.
  3.    Both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> Exceptions are not suitable for critical points in code.

If there is many number of exceptions in the program means, We have to use multiple catch 

statement and it is hard to keep track of the program.


Question 3.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
void PrintSequence(int StopNum)
4.
{
5.
int Num;
6.
Num = 1;
7.
while (true)
8.
{
9.
if (Num >= StopNum)
10.
throw Num;
11.
cout
  1.    Exceptions are not suitable for critical points in code.
  2.    Exception are suitable for critical points in code.
  3.    Both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> Exceptions are not suitable for critical points in code.

Answer:c
Explanation:In this program, We are printing one and raising a exception at 2.
Output:
$ g++ gex4.cpp
$ a.out
1
exception: 2


Question 4.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
void test(int x)
4.
{
5.
try
6.
{
7.
if (x > 0)
8.
throw x;
9.
else
10.
throw 'x';
11.
}
12.
catch(int x)
13.
{
14.
cout
  1.    integer:10character:x
  2.    integer:10
  3.    character:x
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> integer:10character:x

We are passing the integer and character and catching it by using multiple catch statement.
Output:
$ g++ gex3.cpp
$ a.out
integer:10character:x


Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int a = 10, b = 20, c = 30;
6.
float d;
7.
try
8.
{
9.
if ((a - b) != 0)
10.
{
11.
d = c / (a - b);
12.
cout
  1.    10
  2.    -3
  3.    15
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> -3

We are manipulating the values, if there is any infinite value means, it will raise an exception.
Output:
$ g++ gex2.cpp
$ a.out
-3


Question 6.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
try
6.
{
7.
throw 1;
8.
}
9.
catch (int a)
10.
{
11.
cout
  1.    No exception
  2.    exception number
  3.    exception number: 1
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> exception number: 1

If we caught a integer value means, there will be an exception, if it is not a integer, there will 

not be a exception.
Output:
$ g++ gex1.cpp
$ a.out
exception number: 1


Question 7.

How many runtime error messages associated with exception?


  1.    2
  2.    4
  3.    5
  4.    infinite
 Discuss Question
Answer: Option B. -> 4

There are four runtime error messages associated with exceptions.They are overflow_error, 

range_error, system_error and underflow_error.


Question 8.

How many types of exception handling are there in c++?


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer: Option B. -> 2

There are two types of exception handling in c++. They are synchronous exception handling and 

asynchronous exception handling.


Question 9.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
double a = 10, b = 5, res;
6.
char Operator = '/';
7.
try
8.
{
9.
if (b == 0)
10.
throw "Division by zero not allowed";
11.
res = a / b;
12.
cout
  1.    10
  2.    2
  3.    Bad Operator
  4.    10 / 5 = 2
 Discuss Question
Answer: Option D. -> 10 / 5 = 2

In this program, We are dividing the two variables and printing the result. If any one of the operator 

is zero means, it will arise a exception.
Output:
$ g++ gex.cpp
$ a.out
10 / 5 =2


Question 10.

Which block should be placed after try block?


  1.    catch
  2.    throw
  3.    either catch or throw
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> catch

None.


Latest Videos

Latest Test Papers