#include<stdio.h>
void swap(int *a,int *b);
void main()
{ int x,y;
x=10;
y=20;
printf("Before swapping:x=%d y=%d\n",x,y);
swap(&x,&y);
printf("After swapping:x=%d y=%d\n",x,y);
}
void swap(int *a,int *b)
{ int t;
t=*a;
*a=*b;
*b=t;
}
程序运行结果如下:
Before swapping:x=10 y=20
After swapping:x=20 y=10