Forward declarations

It is sometimes useful to be able to use something in a C program file before its declaration. This is called a forward declaration. It can occur quite often when one function calls another which can then call the first again. This is called mutual recursion. When a forward declaration is used, the function which is used must be externally visible, i.e. global and not static.
#include <stdio.h>

long factorial(long); /* A forward declaration */

void main() {
   int i;
   for (i=0;i<=10;i++) printf("%2d! = %ld\n",i,factorial(i));
}

long factorial(long number) {
   if (number<=1)  return 1;
   return(number*factorial(number-1));
}
Plain text version for to compile
Next - Referring to locations (Pointers).

Back to Contents page.