57-用函数改变变量的值-2(用指针)

代码 

#include 
void swap(int *pa,int *pb)
{
	printf("swap is using!\n");
	int temp;
	temp=*pa;
	*pa=*pb;
	*pb=temp;
}
int main()
{
	int a=10;
	int b=20;
	printf("a=%d, b=%d\n",a,b);
	
	swap(&a,&b);
	printf("After exchanging:\na=%d, b=%d\n",a,b);
	
	return 0;
}

运行结果

a=10, b=20
swap is using!
After exchanging:
a=20, b=10

你可能感兴趣的:(c语言经典100题,c语言)