#include <stdio.h>
void swap_v(int x, int y);
void swap_p(int *x, int *y);
void swap_r(int &x, int &y);
int main(void){
int x, y;
x=5;
y=0;
printf("before x=%d, y=%d\n",x,y);
swap_v(x,y);
// swap_p(&x,&y); /* ポインタ引数版を使う時はこの行を有効に */
// swap_r(x,y); /* 参照引数版を使う時はこの行を有効に */
printf("after x=%d, y=%d\n",x,y);
return 0;
}
void swap_v(int x, int y){
int tmp;
tmp = y;
y = x;
x = tmp;
}
void swap_p(int *x, int *y){
int tmp;
tmp = *y;
*y = *x;
*x = tmp;
}
void swap_r(int &x, int &y){
int tmp;
tmp = y;
y = x;
x = tmp;
}
|