fork download
  1. #include <iostream>
  2.  
  3. void swap(int &a, int &b)
  4. {
  5. int tmp = a;
  6. a = b;
  7. b = tmp;
  8. }
  9.  
  10. int main()
  11. {
  12. int a = 10;
  13. int b = 20;
  14.  
  15. std::cout<< "[a, b]: ["<< a<< ", "<< b<< "]\n";
  16.  
  17. swap(a, b);
  18.  
  19. std::cout<< "[a, b]: ["<< a<< ", "<< b<< "]\n";
  20. return 0;
  21. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
[a, b]: [10, 20]
[a, b]: [20, 10]