Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

What are the perdefined exceptions in c++?


  1.    Memory allocation errors
  2.    I/O errors
  3.    both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> both a & b

None.


Question 2.

Which of the following is best to include under try block?


  1.    static values
  2.    const values
  3.    dynamic allocations
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> dynamic allocations

Because the dynamic allocations can change at any time, So it is best to include in try block.


Question 3.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
class Test
5.
{
6.
public:
7.
Test();
8.
virtual ~Test();
9.
};
10.
int main()
11.
{
12.
Test *ptrvar = NULL;
13.
try
14.
{
15.
cout
  1.    No exception arises
  2.    The object is null
  3.    Error
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> The object is null

As there is no object in the class, It is arising an exception in the program.
Output:
$ g++ std4.cpp
$ a.out
The object is null


Question 4.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
class shape
5.
{
6.
public:
7.
virtual void myvirtualfunc() const {}
8.
};
9.
class mytriangle: public shape
10.
{
11.
public:
12.
virtual void myvirtualfunc() const
13.
{
14.
};
15.
};
16.
int main()
17.
{
18.
shape shape_instance;
19.
shape &ref_shape = shape_instance;
20.
try
21.
{
22.
mytriangle &ref_mytriangle = dynamic_cast(ref_shape);
23.
}
24.
catch (bad_cast)
25.
{
26.
cout
  1.    Caught standard exception
  2.    No exception arises
  3.    Caught: bad_cast exception
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Caught: bad_cast exception

As we are not able to allocate the values by using dynamic cast,
So it is arising an exception.
Output:
$ g++ std3.cpp
$ a.out
Caught: bad_cast exception


Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
char* ptr;
6.
unsigned long int a = (size_t(0) / 3);
7.
cout
  1.    0
  2.    2
  3.    bad_alloc
  4.    depends on compiler
 Discuss Question
Answer: Option A. -> 0

As we are dividing the zero by three, it is returning 0.
Output:
$ g++ std2.cpp
$ a.out
0


Question 6.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
try
7.
{
8.
int* myarray= new int[1000];
9.
cout
  1.    Allocated
  2.    Standard exception:
  3.    bad_alloc
  4.    Depends on memory
 Discuss Question
Answer: Option D. -> Depends on memory

Variable will be allocated depends on the available space in the memory, If there is no space 

means, It will throw an exception.
Output:
$ g++ std1.cpp
$ a.out
Allocated


Question 7.

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


  1.    9
  2.    5
  3.    6
  4.    7
 Discuss Question
Answer: Option A. -> 9

There are nine standard exceptions in c++. They are bad_alloc, bad_cast, bad_exception, 

bad_function_call, bad_typeid, bad_weak_ptr, ios_base::failure, logic_error and runtime_error.


Question 8.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
class myexc: public exception
5.
{
6.
virtual const char* what() const throw()
7.
{
8.
return "My exception";
9.
}
10.
} myex;
11.
int main ()
12.
{
13.
try
14.
{
15.
throw myex;
16.
}
17.
catch (exception& e)
18.
{
19.
cout
  1.    My
  2.    My exception
  3.    No exception
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> My exception

This is a type of exception arising in the class. We can call this
also as a standard exception.
Output:
$ g++ std.cpp
$ a.out
My exception


Question 9.

Where are standard exception classes grouped?


  1.    namespace std
  2.    error
  3.    catch
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> namespace std

As these are standard exceptions, they need to be defined in the standard block, So it is defined 

under namespace std.


Question 10.


Which header file is used to declare the standard exception?


a) #include<exception>
b) #include<except>
c) #include<error>
d) none of the mentioned
  1.    namespace std
  2.    error
  3.    catch
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> namespace std

Answer:a
Explanation:None.


Latest Videos

Latest Test Papers