Skip to content

Instantly share code, notes, and snippets.

@hankliu5
Created October 24, 2016 23:16
Show Gist options
  • Save hankliu5/d4914851970e4a93e7137a894f31e825 to your computer and use it in GitHub Desktop.
Save hankliu5/d4914851970e4a93e7137a894f31e825 to your computer and use it in GitHub Desktop.
#include <iostream>
void swap(int *x, int *y) {
int temp = *x;
printf("the value of temp: %d\n", temp);
*x = *y;
*y = temp;
}
void wrong_swap(int x, int y) {
int temp = x;
x = y;
y = temp;
}
int main() {
int i = 10, j = 20;
printf("Before Swapping\n%d %d\n", i, j);
swap(&i, &j);
printf("After Swapping\n%d %d\n", i, j);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment