C++ Quiz70 of 173
Difficulty:
⬅️ Prev: 158Quiz ID: 159Next: 160 ➡️

According to the C++23 standard, what is the output of this program?

#include <iostream>

int i;

void f(int x) {
    std::cout << x << i;
}

int main() {
    i = 3;
    f(i++);
}
Hint

Is there a sequence point associated with a function call?

Reveal answer

34

Explanation

According to §[intro.execution]¶11 in the standard, when calling a function:

(...) every argument expression (...) [is] sequenced before every expression or statement in the body of the called function.

Hence, in the expression f(i++), f is called with a parameter of the original value of i, but i is incremented before entering the body of f.

⬅️ Prev: 158Quiz ID: 159Next: 160 ➡️