Vidyalelo
C++ Programming · Q97

C++ miscellaneous

Programming · C++ Programming · question 97

Q97

What will be the output of the following C++ code? #include using namespace std; class Base protected: int a; public: Base() a = 34; Base(int i) a = i; virtual ~Base() if (a < 0) throw a; virtual int getA() if (a < 0) throw a; ; int main() try Base b(-25); cout << endl << b.getA(); catch (int) cout << endl << "Illegal initialization";

A.
Illegal initialization
B.
Terminate called after throwing an instance of 'int'
Answer
C.
Illegal initialization & terminate called after throwing an instance
D.
initialization

Answer: Option B

Solution

Answer: Option B
No explanation is given for this question Let's Discuss on Board