fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int k = 10;
  6. int& foo = k;
  7. auto bar = foo; //value of foo is copied!
  8. bar = 5; //foo / k won't be 5
  9. cout << "bar : " << bar << " foo : " << foo << " k : " << k << endl;
  10. auto& ref = foo;
  11. ref = 5;
  12. cout << "bar : " << bar << " foo : " << foo << " k : " << k;
  13. return 0;
  14. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
bar : 5 foo : 10 k : 10
bar : 5 foo : 5 k : 5