ProgrammingVery hardProduct-company placement · C++

What is printed?

What is printed?
int main() {
    try { throw 1; }
    catch (long)   { cout << "L"; }
    catch (double) { cout << "D"; }
    catch (...)    { cout << "?"; }
}
  1. A. L
  2. B. D
  3. C. ?
  4. D. Compile-time error

Correct answer: C. ?

Handler matching allows only derived-to-base and pointer/qualification conversions, never arithmetic conversions. An int matches neither long nor double, so only catch (...) handles it.

More OOP with C++ and Java questions

Exams that ask this topic