#include <iostream>
using namespace std;
int& get2()
{
int a = 10;
return a;
}
void main()
{
int c = 0;
c = get2();
int& b = get2();
cout << "c:" << c << " " << "b:" << b << endl;
}
b相当于接受一个地址,函数返回后这个地址的变量不是被销毁了吗?为何b还能正常输出?
求大神指教!
...全文
1015打赏收藏
C++中关于函数返回值是一个引用的问题
#include using namespace std; int& get2() { int a = 10; return a; } void main() { int c = 0; c = get2(); int& b = get2(); cout << "c:" << c << " " << "b:" << b << endl; } b相当于接受一个地址,函数返回后这个地址的变量不是被销毁了吗?为何b还能正常输出? 求大神指教!