What does “static” means in a C program?

A “static” variable inside a function keeps its value between invocations.

For example:

#include <stdio.h>

void printValue();

int main()
{
  int i;
  for(i=0; i<5; i++)
  printValue();

  return 0;
}

void printValue()
{
  static int x = 0;
  int y =0;

  x++;
  y++;

  printf("x=%d y=%d\n", x, y);
}

 

Printout:

output

A “static” global variable or a function is “seen” only in the file it’s declared