When are variables removed from memory in C++?

前端 未结 11 1137
梦如初夏
梦如初夏 2020-12-16 06:54

I\'ve been using C++ for a bit now. I\'m just never sure how the memory management works, so here it goes:

I\'m first of all unsure how memory is unallocated in a fu

11条回答
  •  伪装坚强ぢ
    2020-12-16 07:18

    In C,C++ local variables have automatic storage class and are stored in Stack.

    When function returns then stack gets unwound and locals are no more accessible, but they still persist in memory and that's the reason when u define a variable in function it may contain garbage value.

    It is just stack pointer manipulation in stack and on memory for local is removed actually.

提交回复
热议问题