C++ interview questions part 18

C++ interview questions part 18

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. What are the different types of exceptions?

Correct Answer is : Either single or double quotes

2. Which keyword is used to throw an exception?

Correct Answer is : Both 1 and 2

3. What is the output of the following C++ code? #include #include #include using namespace std;   void func(int a, int b) {   if(b == 0){ throw "This value of b will make the product zero. " "So please provide positive values.\n"; } else{ cout<<"Product of "<
Correct Answer is : 2


4. What is the output of the following C++ code? #include #include #include using namespace std; void func(int a, int b) { if(b == 0){ throw "This value of b will make the product zero. " "So please provide positive values.\n"; } else{ cout<<"Product of "<
Correct Answer is : comments are parts of the source code disregarded by the compiler


5. What is Re-throwing an exception means in C++?

Correct Answer is : single line and multi-line

6. What is the output of the following C++ code? #include #include #include using namespace std; void func(int a, int b) { if(b < 1){ throw b; } else{ cout<<"Product of "<
Correct Answer is : compile time error


7. Where should we place catch block of the derived class in a try-catch block?

Correct Answer is : /* …. */

8. What happens when this C++ program is compiled? #include #include #include using namespace std; class A { int a; public: A(){} };   class B: public A { int b; public: B(){} };   void func() { B b; throw b; }   int main() { try{ func(); } catch(A a){ cout<<"Caught A Class\n"; } catch(B b){ cout<<"Caught B Class\n"; } }

Correct Answer is : distinguishes between comments and code

9. What is the output of the following C++ code? #include #include #include using namespace std; class A { int a; public: A(){} };   class B: public A { int b; public: B(){} };   void func() { B b; throw b; }   int main() { try{ func(); } catch(A a){ cout<<"Caught A Class\n"; } catch(B b){ cout<<"Caught B Class\n"; } }

Correct Answer is : segmentation fault

10. What is the output of the following C++ code? #include #include #include using namespace std; class A { int a; public: A(){} };   class B: public A { int b; public: B(){} };   void func() { B b; throw b; }   int main() { try{ func(); } catch(B b){ cout<<"Caught B Class\n"; } catch(A a){ cout<<"Caught A Class\n"; } }

Correct Answer is : 110

11. What is the output of the following C++ code? #include #include #include using namespace std; class A { int a; public: A(){} }; class B: public A { int b; public: B(){} };   void func() { B b; throw b; } int main() { try{ func(); } catch(B *b){ cout<<"Caught B Class\n"; } catch(A a){ cout<<"Caught A Class\n"; } }

Correct Answer is : 13

12. What id the syntax for catching any type of exceptions?

Correct Answer is : It will not return value to its caller

13. What is the output of the following C++ code? #include #include #include using namespace std; class A { int a; public: A(){} };   class B: public A { int b; public: B(){} };   void func1() { B b; throw b; }   void func2() { A a; throw a; }   int main() { try{ func1(); } catch(...){ cout<<"Caught All types of exceptions\n"; } try{ func2(); } catch(B b){ cout<<"Caught All types of exceptions\n"; } }

Correct Answer is : 45337

14. Uncaught exception leads to ______________

Correct Answer is :

15. An uncaught handler returns to _______________

Correct Answer is : complex variable_name;

16. Header file used for exception handling in C++?

Correct Answer is : real()

17. The C++ code which causes abnormal termination/behaviour of a program should be written under _________ block.

Correct Answer is : imag()

18. Exception handlers are declared with ____________ keyword.

Correct Answer is : Complex number is: 3 + 5i

19. Which of the following statements are correct about Catch handler? i. It must be placed immediately after the try block ii. It can have more than one parameters iii. There must be one and only one catch handler for every try block iv. There can be multiple catch handler for a try block v. General catch handler can be kept anywhere after try block.

Correct Answer is : abs()

20. In nested try-catch block, if the inner catch block gets executed, then______________

Correct Answer is : Absolute value is: 5.83095

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon