为什么这个交换方法不起作用
void swap(int *x,int *y){
int *temp;
temp = x;
x = y;
y = temp;
}
为什么?我认为它和普通的一样..
最佳答案
C 按值传递函数参数:您只是交换指针的副本。
如果你想交换两个int
:
void swap(int *x,int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
关于c - 交换功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696991/