Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int num = 3;
    string str_bad = "wrong number used";
    try
    {
        if ( num == 1 )
        {       
            throw 5;
        }
        if ( num == 2 )
        {
            throw 1.1f;
        }
        if ( num != 1 || num != 2 )
        {    
            throw str_bad;
        }
    }
    catch (int a)
    {
        cout << "Exception is: " << a << endl;
    }
    catch (float b)
    {
        cout << "Exception is: " << b << endl;
    }
    catch (...)
    {
        cout  << str_bad << endl;
    }
    return 0;
}

A. Exception is 5

B. Exception is 1.1f

C. Wrong number used

D. Exception is 1.6g

Answer: Option C


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it