A static function in C is a function that has a scope that is limited to its object file. This means that the static function is only visible in its object file. A function can be declared as a static function by placing the static keyword before the function name.
A program that demonstrates static functions in C is given as follows ?
Example*
#include <stdio.h>
static void staticFunc(void){
printf("Inside the static function staticFunc() ");
}
int main()
{
staticFunc();
return 0;
}
*Output
The output of the above program is as follows ?
Inside the static function staticFunc()
In the above program, the function
staticFunc()
is a static function that prints ”Inside the static function
staticFunc()
”. The
main()
function calls
staticFunc()
. This program works correctly as the static function is called only from its own object file.