What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void test(int x)
{
try
{
if (x > 0)
throw x;
else
throw 'x';
}
catch(int x)
{
cout<<"integer:"<<x;
}
catch(char x)
{
cout << "character:" << x;
}
}
int main()
{
test(10);
test(0);
}
#include <iostream>
using namespace std;
void test(int x)
{
try
{
if (x > 0)
throw x;
else
throw 'x';
}
catch(int x)
{
cout<<"integer:"<<x;
}
catch(char x)
{
cout << "character:" << x;
}
}
int main()
{
test(10);
test(0);
}A. integer:10character:x
B. integer:10
C. character:x
D. character:10
Answer: Option A

Join The Discussion