Recursive function with static variable : Function Recursive « Function « C / ANSI-C






Recursive function with static variable

#include <stdio.h>

void f(void);

int main(void)
{
  f();

  return 0;
}

void f(void)
{
  static int s = 0;

  s++;

  if(s == 10) 
      return;
  printf("%d ", s);
  f(); /* recursive call */
}


           
       








Related examples in the same category

1.A recursive power functionA recursive power function
2.Calculating factorials using recursion
3.Prints out Fibonacci numbersPrints out Fibonacci numbers
4.Recursive function call
5.Function: Recursive call
6.Copy string using recursion