Question discussion

What is the output of the following C++ program?#include using namespace std; struct R { ~R() { cout

1559Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C++ program?

#include <iostream>
using namespace std;
struct R { ~R() { cout << "d"; } };
void f() { R r; throw 1; }
int main() {
    try { f(); }
    catch (int) { cout << "c"; }
    cout << "e";
}
  • Acde
  • Bdce
  • Cce
  • Ddc
Correct answer: B

Explanation

During stack unwinding the local object r is destroyed (d) before the handler runs (c), after which execution continues with e.

Discussion 0

Nobody has replied yet. Start the discussion!