Advertisement
193030

Parameters passing - Call by reference

Aug 9th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void swap(int &x, int &y)
  6. {
  7.     int temp = x;
  8.     x = y;
  9.     y = temp;
  10. }
  11. int main()
  12. {
  13.   int a = 10;
  14.   int b = 40;
  15.  
  16.   swap(a, b);
  17.   cout << a << " " << b << endl;
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement