Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Requires: nothing
- //Modifies: x and y
- //Effects: will swap the values of x and y
- // if x = 7 and y = 13 upon entry
- // when this function ends, x = 13 and y = 7
- void swap(int & x, int & y)
- {
- int temp;
- temp = x; //Assigns x to the new declared int
- x = y; //Makes x = y
- y = temp; //Assigns y to temp, swapping it
- }
- Then I try to do:
- int main()
- {
- int a = 13;
- int b = 7;
- int c = 50;
- int d = 5;
- int e = 33;
- int f = 28;
- swap(a, b);
- swap(c, d);
- swap(e, f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement