ExamVeda
Login
Home
C plus plus miscellaneous
?

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

Answer & Solution
Correct Answer: Option D
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.