Local variable still exists after function returns

前端 未结 5 2141
暖寄归人
暖寄归人 2021-01-05 20:00

I thought that once a function returns, all the local variables declared within (barring those with static keyword) are garbage collected. But when I am trying

5条回答
  •  太阳男子
    2021-01-05 20:14

    It's undefined behavior, anything can happen, including appearing to work. The memory probably wasn't overwritten yet, but that doesn't mean you have the right to access it. Yet you did! I hope you're happy! :)

提交回复
热议问题