开发者

c++ warning: address of local variable

Merged with Can a local variable's memory be accessed outside its scope?. 开发者_开发技巧
int * ref () {

 int tmp = 100;
 return &tmp;
}

int main () {

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

I know the function ref () is allocated stack space. It will get destroyed as soon as the function exits. So the complier will give warning information. But my question is why the returning result is still correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜