【发布时间】:2022-01-14 20:22:56
【问题描述】:
这是我的代码:
使用命名空间标准;
// 如果内存是静态分配的,那么在函数返回且堆栈消失后,您将无法访问内存地址。
int* function(int x)
{
int *x_ptr = &x;
return x_ptr;
}
int main()
{
int x=10;
int *x_ptr = function(x);
cout<<*x_ptr<<endl;
}
【问题讨论】:
标签: c++ heap-memory stack-memory