【发布时间】:2011-02-04 12:16:05
【问题描述】:
考虑这段代码:
const char* someFun() {
// ... some stuff
return "Some text!!"
}
int main()
{
{ // Block: A
const char* retStr = someFun();
// use retStr
}
}
在函数someFun() 中,"Some text!!" 存储在哪里(我认为它可能在 ROM 的某个静态区域中)以及它的 scope 生命周期是多少?
retStr指向的内存会在整个程序中被占用还是在A块退出后被释放?
【问题讨论】:
标签: c++ c lifetime string-literals