If I have the following code:
void bar(){
int x = 1;
foo();
}
void foo(){
while(true);
}
What happens to the memory int x
used in bar()
when foo()
is called? Is it freed? I know that the memory is freed if the function returns, however in this case the function simply never returns.
If I used this code, in which bar
calls foo
which, in turn, calls bar
and so on, would the program eventually run out of memory, or would the old instances of the functions be replaced by the new ones?
void bar(){
int x = 1;
foo();
}
void foo(){
int y = 1;
bar();
}