My Report

C++ Programming Practice Test 6


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which is used to solve the memory management problem in c++?

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

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

4. What is the main purpose of the constructor?

5. What is meant by exception specification?

6. What will be the output of the following C++ code?

    #include <iostream>
    #include <exception>
    using namespace std;
    class myexc: public exception
    {
        virtual const char* what() const throw()
        {
            return "My exception";
        }
    } myex;
    int main () 
    {
        try
        {
            throw myex;
        }
        catch (exception& e)
        {
            cout << e.what() << endl;
        }
        return 0;
    }

7. An uncaught handler returns to _______________

8. 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;
}

9. What will be the output of the following C++ code?

  
    #include <iostream>
    using namespace std;
    class Test1 
    { 
    };
    class Test2 : public Test1 { };
    void Funct();
    int main()
    {
        try
        {
            Funct();
        }
        catch (const Test1&)
        {
            cerr << "Caught a exception" << endl;
        }
        return 0;
    }
    void Funct()
    {
        throw Test2();
    }

10. How to handle the exception in constructor?


 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.