0
Why can I return a local variable from a function? Shouldn't local variables be deleted from the stack after function execution?
See the example code. Why does it work? If I return a local variable, said variable shouldn't be available anymore after the function exits? Or am I missing something? https://code.sololearn.com/c9f2ZqaJxdqC/?ref=app
2 odpowiedzi
+ 9
You are not returning the local variable, instead you are returning the value that is inside that variable.
When value is returned, the variable gets deleted from the stack like you said.
+ 2
Oh boy, I think I asked before thoroughly thinking about it. The result is returned by value, not by reference?