Possible Duplicate:
What are the differences between pointer variable and reference variable in C++?
What's the meaning of * and & when applied to variable names?
在这种情况下试图理解“&
”的含义
void af(int& g)
{
g++;
cout<<g;
}
如果您调用此函数并传递变量名 - 它的行为将与普通 void(int g)
相同。我知道,当您编写 &g
时,这意味着您正在传递变量 g
的地址。但是在这个示例中它意味着什么?
最佳答案
这意味着你通过引用传递变量。
其实在一个类型的声明中,就是引用的意思,就像:
int x = 42;
int& y = x;
声明对x
的引用,称为y
。
关于c++ - "&"变量类型后的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11604190/