When are variables removed from memory in C++?

前端 未结 11 1163
梦如初夏
梦如初夏 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:11

    In this case both num and temp are local to this function. When the function is called the number passed into num is copied from the caller to a variable on the stack. Temp is then created on the stack. When you return the value of num is copied back to the caller, and the temp and num variables used in the function are dropped.

提交回复
热议问题