【发布时间】:2010-08-03 17:51:48
【问题描述】:
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;
}
【问题讨论】:
标签: c++ pass-by-reference pass-by-value