IBM在下面的示例(包括源文件)中解释了C++通过引用传递。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;
}
你忘了命名你的第二个swapnum方法swapByVal – RickNotFred 2010-08-03 18:04:08
@RichNotFred - 我会说它仍然非常接近星期一,所以请原谅我:)。虽然编辑。 – JonH 2010-08-03 18:05:49