Recursion
January 13th, 2010
1 comment
Check out this C code:
void forever(void)
{
forever();
}
Seems straightforward enough. The function calls itself, right? That’s recursion—when a function calls itself. In this case, it never stops calling itself. Probably on your implementation, this will eventually cause a callstack overflow and the program will die. (When you make a function call, the return address and function parameters have to be stored somewhere, and often they are stored on a stack. Each time you recursively call a function, more and more return addresses and parameters are pushed on the stack.)