Possible Duplicate:
What is a stack overflow error?
look the code below.
#include <iostream>
using namespace std;
void leave(double as){
cout<<as;
leave(as);
}
int main(){
double x=1234.5;
leave(x);
cout<<"hellow";
}
When this code executes their is no way to stop. it should print the value x
over and over again. But practically, this works for about 20 secs and close automatically. It doesn't print the line hellow
. What is the reason for it? In windows task manager I can realize that the memory used with the application will increase. but I have allocated memory for x
within the main function only, so will the function allocate memory for x
over and over again. Is this type of situation called a memory leak? if its so what lines should be added to prevent it?
If I change the code as below it shows the word hellow
without going through the function over and over again:
void leave(){
leave();
}
int main(){
leave();
cout<<"hellow";
}
How to explain these situations?