Node:Recursion, Next:, Previous:Data structures, Up:Top



Recursion

The program that swallowed its tail.

This chapter is about functions that call themselves. Consider the program below:

#include <stdio.h>

void black_hole()
{
  black_hole();
}

/* To shorten example, not using argp */
int main ()
{
  black_hole();
  return 0;
}

The main function calls the black_hole function, which calls itself, which calls itself, which calls... Once the control flow enters black_hole, it will never exit. This kind of function is called a recursive function, and a function's act of calling itself is called recursion.