adplus-dvertising

Welcome to the Namespaces and Exceptions in C++ MCQs Page

Dive deep into the fascinating world of Namespaces and Exceptions in C++ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Namespaces and Exceptions in C++, a crucial aspect of Object Oriented Programming Using C++. In this section, you will encounter a diverse range of MCQs that cover various aspects of Namespaces and Exceptions in C++, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Object Oriented Programming Using C++.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Namespaces and Exceptions in C++. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Object Oriented Programming Using C++.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Namespaces and Exceptions in C++. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Namespaces and Exceptions in C++ MCQs | Page 2 of 2

Q11.
To where does the program control transfers when exception is arised?
Discuss
Answer: (b).handlers
Q12.
Which key word is used to check exception in the block of code?
Discuss
Answer: (c).try
Q13.
What will happen when the exception is not caught in the program?
Discuss
Answer: (a).error
Q14.
What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
        int age = 0;
        try 
        {
            if (age < 0) 
            {
                throw "Positive Number Required";
            }
            cout << age;
        }
        catch(const char *Message)
        {
            cout << "Error: " << Message;
        }
        return 0;
    }
Discuss
Answer: (a).0
Q15.
What is the output of this program?
    #include <iostream>
    using namespace std;
    void PrintSequence(int StopNum)
    {
        int Num;
        Num = 1;
        while (true) 
        {
            if (Num >= StopNum)
                throw Num;
            cout << Num;
            Num++;
        }
    }
    int main(void)
    {
        try 
        {
            PrintSequence(20);
        }
        catch(int ExNum)
        {
            cout << "Caught an exception with value: " << ExNum;
        }
        return 0;
    }
Discuss
Answer: (c).prints first 19 numbers and throws exception at 20
Q16.
What is the output of this program?
    #include <iostream>
    using namespace std;
    double division(int a, int b)
    {
        if (b == 0) 
        {
            throw "Division by zero condition!";
        }
        return (a / b);
    }
    int main ()
    {
        int x = 50;
        int y = 2;
        double z = 0;
        try 
        {
            z = division(x, y);
            cout << z;
        }
        catch(const char *msg) 
        {
            cerr << msg;
        }
        return 0;
    }
Discuss
Answer: (a).25
Q17.
What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
        char* buff;
        try 
        {
            buff = new char[1024];
            if (buff == 0)
               throw "Memory allocation failure!";
            else
               cout << sizeof(buff) << "Byte successfully allocated!"<<endl;
        }
        catch(char *strg)
        {
            cout<<"Exception raised: "<<strg<<endl;
        }
        return 0;
    }
Discuss
Answer: (d).Depends on the size of data type
Q18.
What is the output of this program?
    #include <iostream>
    using namespace std;
    void Funct();
    int main()
    {
        try 
        {
            Funct();
        }
        catch(double) 
        {
            cerr << "caught a double type..." << endl;
        }
        return 0;
    }
    void Funct()
    {
        throw 3;
    }
Discuss
Answer: (c).abnormal program termination
Q19.
What is the output of this program?
    #include <iostream>
    #include <exception>
    using namespace std;
    int main()
    {
        try 
        {
            int * array1 = new int[100000000];
            int * array2 = new int[100000000];
            int * array3 = new int[100000000];
            int * array4 = new int[100000000];
            cout << "Allocated successfully";
        }
        catch(bad_alloc&) 
        {
            cout << "Error allocating the requested memory." << endl;
        }
        return 0;
    }
Discuss
Answer: (c).Depends on the memory of the computer
Discuss
Answer: (a).calls the standard library function terminate()
Page 2 of 2

Suggested Topics

Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!