#include <stdio.h>
#include <stdlib.h>
//这个方法是没有进行交换的
void swap(int p,int q){
int temp;
temp = p;
p = q;
q = temp;
}
main(){
int i = 5;
int j = 3;
swap(5,3);
printf("i = %d\n",i);
printf("j = %d\n",j);
system("pause");
}
#include <stdio.h>
#include <stdlib.h>
//这个方法交换成功了
void swap1(int* p,int* q){
int temp;
temp = *p;
*p = *q;
*q = temp;
}
main(){
int i = 5;
int j = 3;
swap(5,3);
swap1(&i,&j);
printf("i = %d\n",i);
printf("j = %d\n",j);
system("pause");
}