Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. //Requires: nothing
  2. //Modifies: x and y
  3. //Effects: will swap the values of x and y
  4. //         if x = 7 and y = 13 upon entry
  5. //         when this function ends, x = 13 and y = 7
  6. void swap(int & x, int & y)
  7. {
  8.     int temp;
  9.     temp = x; //Assigns x to the new declared int
  10.     x = y; //Makes x = y
  11.     y = temp; //Assigns y to temp, swapping it
  12. }
  13.  
  14.  
  15. Then I try to do:
  16.  
  17. int main()
  18. {
  19. int a = 13;
  20.     int b = 7;
  21.     int c = 50;
  22.     int d = 5;
  23.     int e = 33;
  24.     int f = 28;
  25.     swap(a, b);
  26.     swap(c, d);
  27.     swap(e, f);
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement