fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void swap(int i, int j) {
  5. int temp = i;
  6. i = j;
  7. j = temp;
  8. }
  9. int main() {
  10. int a = 110;
  11. int b = 786;
  12. cout << "Before swapping the value" << endl;
  13. cout << "'a' stores the value : " << a << endl;
  14. cout << "'b' stores the value : " << b << endl;
  15. swap(a,b);
  16. cout << "\nAfter swapping the value" << endl;
  17. cout << "'a' stores the value : " << a << endl;
  18. cout << "'b' stores the value : " << b << endl;
  19. swap(a, b);
  20. cout << "\nAnd back again swapping the value" << endl;
  21. cout << "'a' stores the value : " << a << endl;
  22. cout << "'b' stores the value : " << b << endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Before swapping the value
'a' stores the value : 110
'b' stores the value : 786

After swapping the value
'a' stores the value : 110
'b' stores the value : 786

And back again swapping the value
'a' stores the value : 110
'b' stores the value : 786