Knowee
Questions
Features
Study Tools

What will be the output of the following program?12345678910111213141516171819#include <iostream>#include <exception>using namespace std;class myexception : public exception{ virtual const char* what() const throw(){ return "Exception arised!"; }} myex;int main(){ try{ throw myex; } catch (exception& e){ cout << e.what() << endl; } return 0;}Marks : 1Negative Marks : 0Answer hereException arised!Compile Time ErrorNothing will be printed0

Question

What will be the output of the following program?12345678910111213141516171819#include <iostream>#include <exception>using namespace std;class myexception : public exception{ virtual const char* what() const throw(){ return "Exception arised!"; }} myex;int main(){ try{ throw myex; } catch (exception& e){ cout << e.what() << endl; } return 0;}Marks : 1Negative Marks : 0Answer hereException arised!Compile Time ErrorNothing will be printed0

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the program will be "Exception arised!". This is because the program throws an exception of type "myexception", and the catch block catches it and prints the message associated with it, which is "Exception arised!".

Similar Questions

What will be the output of the following program?1234567891011121314151617181920#include <stdio.h>void one();void two();void one() { for(int i = 0; i < 2; i++){ two(); }}void two() { printf("TWO ");}int main(){ one(); two(); return 0;}

What will be the output of the following program?

What will be the output of the following program?12345678910111213#include <stdio.h> int ren(int n) { if (n == 6) return n; else return 2*ren(n+1);}int main() { printf("%d", ren(2)); return 0;}

What will be the output of the following program?12345678910#include <stdio.h> int main() { int a[10]; *a = 7; *(a+1) = 12; int p = *(a+1) / *a; printf("%d", p); return 0;}

What will be the output of the following code?1234567891011121314151617#include <stdio.h>int main() { int i = 0, product = 10;start: if (i < 4) { product *= (i + 1); i++; if (i != 2) goto start; } printf("%d", product); return 0;}

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.