What are Static Variables and functions in C ?

  • In C, functions are global by default. The “static” keyword before a function name makes it static.
  • Unlike global functions in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static.
  •  Another reason for making functions static can be reuse of the same function name in other files.
  • For example, below function fun() is static.

static int fun(void)

{

  printf("I am a static function ");

}


Source : GeeksforGeeks & GeeksforGeeks