值传递问题。
#include <stdio.h>void swap1(int x, int y)
{
int tmp;
tmp = x;
x = y;
y = tmp;
}
int main()
{ int a=3;
int b=5;
swap1(a,b); //值传递
printf("a=%d,b=%d\n",a,b);
return 0;
}
出来运行结果 a还是3 b还是5,没有替换,请大佬看看
#include <stdio.h> void swap1( int* px, int* py ) { int tmp = *px; *px = *py; *py = tmp; } int main( void ) { int a = 3; int b = 5; swap1( &a, &b ); printf( "a=%d, b=%d\n", a, b ); }