Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
    double Op1 = 10, Op2 = 5, Res;
    char Op;
    try 
    {   
        if (Op != '+' && Op != '-' && Op != '*' && Op != '/')
            throw Op;
        switch(Op)
        {
        case '+':
            Res = Op1 + Op2;
            break;
        case '-':
            Res = Op1 - Op2;
            break;
        case '*':
            Res = Op1 * Op2;
            break;
        case '/':
            Res = Op1 / Op2;
            break;
         }
         cout << "\n" << Op1 << " " << Op << " "<< Op2 << " = " << Res;
     }
     catch (const char n)
     {
         cout << n << " is not a valid operator";
     }
     return 0;
}

A. 15

B. 5

C. 2

D. is not a valid operator

Answer: Option D


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