c - What happens to a function's stack when it returns? -


#include <stdio.h>  void function() {     int stackvar = 10;     printf("stack variable = %d\n", stackvar); }  int main(void) {     function();     return 0; } 

what happens stack frame of function when returns?

firstly, you've edited question dramatically, other answers (somewhat unfairly) no longer relevant. still, answer current question:

what happens stack frame of function when returns?

it seems me lack general feel how stack operates. - going bit crazy here - try analogy might make "click". can imagine stack frame being waves on beach. more nested function calls get, , more data functions have in parameters , local variables, more memory in use. that's waves reaching further beach. scopes exit memory released - use memory put forgotten. waves recede. still, throughout lifetime of program different sequences of functions enter , exit, same memory (level of beach) reused (under water) , forgotten (not under water). bits furthest beach tend covered least , short durations, while stays underwater until weakest point of low tide... things recursive functions aren't tail-recursion optimised can use lot of memory briefly, stack variables created directly in main() stay there until program termination.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -