Define and use static variable : Static « Data Type « C / ANSI-C






Define and use static variable


#include <stdio.h>

void f(void);

int main(void)
{
  int i;

  for(i = 0; i < 10; i++) 
      f();

  return 0;
}

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

  count++;
  printf("count is %d\n", count);
}


           
       








Related examples in the same category

1.Demonstrate the use for permanent and temporary storage
2.Static versus automatic variables
3.Define static variable inside function
4.Find out the address of a static variable in a functionFind out the address of a static variable in a function