Exchange function of the number _

Function implemented using two switched to number,
herein used interchangeably thanks to a pointer, if used
int the Exchange (int X, Y int) {
int I = 0;
I = X;
X = Y;
Y = I;
}
is not exchanged numbers, because the parameter is an argument too was temporary copy of the parameter was modified without changing the argument, the argument will only have to address to the formal parameters, in order to complete the exchange worth

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Exchange(int* x, int* y){
	int i = 0;
	i = *x;
	*x = *y;
	*y = i;
}
int main(){
	int j;
	int m;
	printf("请输入两个数:\n");
	scanf("%d%d", &j, &m);
	Exchange(&j,&m);
	printf("%d %d\n", j, m);
	system("pause");
	return 0;
}

Guess you like

Origin blog.csdn.net/sun_105/article/details/93730678