What are Static functions in C?

C functions are global by default. A function is defined as static by the use of static keyword with the function’s name. The use of a static function is restricted to its object file where it is declared.

Syntax

static int Test(void)
{
printf("Testing the function");
}

Functions are declared static to limit access. This also means that they cannot be used in other files. Only the file in which they are declared has the right to use them. The following example depicts this scenario.

#include<stdio.h>
/* Contents of first file */
static void Educative(void)
{
printf("Educative called");
}
int main()
{
Educative();
return 0;
}

Storing the program in another file:

main.c
Educative.c
#include <stdio.h>
int main()
{
Educative();
return 0;
}

Executing the program gives an error because Educative() is declared in the Educative.c file, so it can only be used through that file.

Free Resources