微信扫一扫

028-83195727 , 15928970361
business@forhy.com

swap() 交换两个数

2016-11-08

#include <stdio.h>

void swap(int *x, int *y)//传入指针
{
	int tmp;
	tmp = *x;
	*x = *y;
	*y = tmp;
}

int main()
{
	int a = 3;
	int b = 5;
	printf("a = %d, b = %d\n", a, b);
	swap(&a, &b);
	printf("a = %d, b = %d\n", a, b);
	return 0;
}