Is it OK to reference an out-of-scope local variable within the same function?

后端 未结 4 886
野性不改
野性不改 2020-12-20 19:25

In this code, I reference the local variable b even though it is out of scope. But I do it from within the same function so it\'s probably still on the stack, r

4条回答
  •  情歌与酒
    2020-12-20 20:06

    No, that's not guaranteed to work. a is dangling once the inner scope is exited, so any dereference of it results in Undefined Behaviour and nothing whatsoever is guaranteed.

提交回复
热议问题