Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

What will be the output of the code mentioned below?

  Shared By: Reuben Brown    Date: Jun 24    Category: C++ Programming    Views: 927

Answer:

8. Consider the following code segment:
void divide(int x, int y)
{
try
{
if(y==0)
throw y;
else
cout<<endl<<"Division result is: " <<x/y<<endl;
}
catch(int)
{
throw;
cout<<endl<<"Caught Divide by zero error inside function";
}
}
int main()
{
try
{
divide(20,0);
}
catch(int)
{
cout<<endl<<"Caught Divide by zero error inside main";
}
return 0;
}
What will be the output of the above code?

Options

a) Caught Divide by zero error inside main
b) Caught Divide by zero error inside main
Caught Divide by zero error inside function
c) Caught Divide by zero error inside function
d) None of the above

Answer : a) Caught Divide by zero error inside main

Share: 
 

Didn't find what you were looking for? Find more on What will be the output of the code mentioned below? Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: