fork download
  1. #include <iostream>
  2.  
  3. void regular_function(int i)
  4. {
  5. i=5; // the outside `i' doesn't change, because `i' is a local copy
  6. }
  7.  
  8. void smart_function(int &i)
  9. {
  10. i=5; // the outside `i' changes to 5, because `i' is a reference
  11. }
  12.  
  13. int main()
  14. {
  15. int var = 10;
  16.  
  17. smart_function(var);
  18. std::cout << var << std::endl;
  19. }
  20.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
5