fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void f1(int x)
  5. {
  6. x = 5;
  7. }
  8.  
  9. void f2(const int& x)
  10. {
  11. const_cast<int&>(x) = 5;
  12. }
  13.  
  14. int main()
  15. {
  16. int i = 0;
  17. cout << "start: " << i << endl;
  18. f1(i);
  19. cout << "after f1: " << i << endl;
  20. f2(i);
  21. cout << "after f2: " << i << endl;
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
start: 0
after f1: 0
after f2: 5