ProgrammingHardProduct-company placement · C++

For the call f(g(), h()) in C++17, which statement is correct?

  1. A. g() is always evaluated before h()
  2. B. h() is always evaluated before g()
  3. C. Their executions may interleave instruction by instruction
  4. D. g() and h() are both evaluated before f runs, but which of them runs first is unspecified

Correct answer: D. g() and h() are both evaluated before f runs, but which of them runs first is unspecified

Function arguments are indeterminately sequenced: each is evaluated completely, without interleaving (C++17), but the order among them is up to the implementation. Side effects must not depend on it.

More OOP with C++ and Java questions

Exams that ask this topic