-1 c++
在下面的代码片段中,当使用&引用变量时,我们得到引用变量所指向的变量的地址,但在函数调用期间,引用变量将在堆栈帧上分配,因此如何获取该地址价值?
#include <iostream>
using namespace std;
void modify(int& x)
{
x=9;
cout<<&x<<endl<<x<<endl;
}
int main() {
int a=8;
modify(a);
cout<<&a<<endl<<a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里&x和&a都打印相同的值,这是变量a的地址,那么有什么方法可以得到参考变量x的地址?
| 归档时间: |
|
| 查看次数: |
245 次 |
| 最近记录: |