IBM 在下面的示例中解释了 C++ 通过引用(包括源代码)。
如果我改为void swapnum...
,void swapnum(int i, int j)
它会变成价值传递吗?
// pass by reference example
// author - ibm
#include <stdio.h>
void swapnum(int &i, int &j) {
int temp = i;
i = j;
j = temp;
}
int main(void) {
int a = 10;
int b = 20;
swapnum(a, b);
printf("A is %d and B is %d\n", a, b);
return 0;
}