C++ Quiz75 of 173
Difficulty:
⬅️ Prev: 163Quiz ID: 174Next: 177 ➡️

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

#include <iostream>

void f(int& a, const int& b) {
  std::cout << b;
  a = 1;
  std::cout << b;
}

int main(){
  int x = 0;
  f(x,x);
}
Hint

Is x const?

Reveal answer

01

Explanation

Both a and b refer to the same variable x.

The fact that b is a const reference does not guarantee that b isn't modified from elsewhere, only that we can't modify it.

⬅️ Prev: 163Quiz ID: 174Next: 177 ➡️