To simplify the understanding I will limit to mentioning just the "stack memory". When a function is called, memory on the stack is reserved for the function that is called. In addition to other elements on the stack, the stack contains the memory for the function parameters and local variables of that function(I am avoiding the mention of heap memory here for simplicity). So, the local variable `a` in your example is on the stack. When the function returns to the caller, the stack memory associated with that function is "freed"(freed is in quotes because the stack elements are not freed but "popped/removed" as in a stack data structure). So how does the value of `a` that was on the stack which is removed when the function returns passed to the calling function? Well, the value of `a` is just copied into the variable from the calling function that is assigned the function value that returns `a`. That is why, if you return a very large object from a function, it becomes a performance issue. But with some latest compilers this is resolved by performing return value optimisation, i.e instead of copying, the value is "moved". There are various techniques to achieve this and is a much broader topic.