ProgrammingHardProduct-company placement · C++
What is printed?
What is printed?
void f() noexcept { }
void g() { }
int main() { cout << noexcept(f()) << noexcept(g()); }- A. 10
- B. 11
- C. 00
- D. 01
Correct answer: A. 10
The noexcept operator is evaluated at compile time from the declarations: f is declared noexcept, g is not (even though its body cannot throw).
More OOP with C++ and Java questions
- What happens when this is compiled? cpp int main() { try { throw 1; } catch (...) { cout << "any"; } catch (int) { cout << "int"; } }
- What is printed? cpp int main() { try { throw runtimeerror("disk full"); } catch (const exception& e) { cout << e.what(); } }
- What is printed? cpp struct E { }; int main() { try { throw new E(); } catch (E&) { cout << "ref"; } catch (E) { cout << "ptr"; } }
- What is printed? cpp int main() { try { throw 1; } catch (long) { cout << "L"; } catch (double) { cout << "D"; } catch (...) { cout <<…
- What is printed? cpp struct E { }; struct F : private E { }; int main() { try { throw F(); } catch (E&) { cout << "E"; } catch (...) {…
- What is printed? cpp struct B { B(int x) { cout << x; } }; struct D : B { using B::B; }; int main() { D d(5); }