15, the number of switching two values (not to use a third variable)

15, the number of switching two values ​​(not to use a third variable)

#include<stdio.h>
void swap(int *x, int *y);
int main(){
	int a, b;
	a=1;
	b=2;
	swap(&a, &b);
	printf("%d %d",a, b);
	return 0;
}
void swap(int *x, int *y){
	//以下关键
	*x=*x+*y;
	*y=*x-*y;
	*x=*x-*y;
}

Here Insert Picture Description

Published 16 original articles · won praise 0 · Views 315

Guess you like

Origin blog.csdn.net/NAU_LHT/article/details/104394482