c ++警告:局部变量的地址

时间:2010-05-19 02:31:20

标签: c++ variables local warnings

int * ref () {

 int tmp = 100;
 return &tmp;
}

int main () {

 int * a = ref();
 cout << *a << endl;
}

我知道函数ref()被分配了堆栈空间。一旦函数退出,它就会被销毁。因此编制者会给出警告信息。 但我的问题是为什么返回的结果仍然正确。

0 个答案:

没有答案
相关问题