void swap(int *x ,int *y);
void swap(int *x ,int *y)
{
int tmp;
tmp = *x;
*x = *y;
*y = tmp;
}
int main()
{
int a = 1;
int b = 2;
printf("[before] a=%d b=%d\r\n",a,b);
swap(&a,&b);
printf("[after] a=%d b=%d\r\n",a,b);
return 0;
}
==============Result==============
(for Code::Block)
[before] a=1 b=2
[after] a=2 b=1
沒有留言:
張貼留言