C++ Quiz9 of 173
Difficulty:
⬅️ Prev: 8Quiz ID: 9Next: 11 ➡️

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

#include <iostream>

int f(int &a, int &b) {
  a = 3;
  b = 4;
  return a + b;
}

int main() {
  int a = 1;
  int b = 2;
  int c = f(a, a);
  std::cout << a << b << c;
}
Hint

Aliasing...

Reveal answer

428

Explanation

When f() is called with a as both parameters, both arguments refer to the same variable. This is known as aliasing. First, a is set to 3, then a is set to 4, then 4 + 4 is returned. b is never modified.

⬅️ Prev: 8Quiz ID: 9Next: 11 ➡️