我有这个交换通过引用传递的整数的函数,它在 C++ 中工作正常,但在 C 中不起作用。
#include <stdio.h>
void swap(int & x, int & y)
{
int z = x;
x = y;
y = z;
}
int main()
{
int a = 0, b = 1;
swap(a, b);
printf("a is now %d\n", a);
printf("b is now %d\n", b);
}
Run Code Online (Sandbox Code Playgroud)
为什么它在 C 中不起作用?