ProgrammingHardProduct-company placement · C++

What is printed?

What is printed?
int main() {
    std::function<int()> f;
    try { cout << f(); }
    catch (const bad_function_call&) { cout << "E"; }
}
  1. A. E
  2. B. 0
  3. C. Undefined behaviour: f is empty
  4. D. Compile-time error: f has no target

Correct answer: A. E

Calling an empty std::function is well defined: it throws std::bad_function_call.

More OOP with C++ and Java questions

Exams that ask this topic