Static variable is a special variable that is stored in the data segment unlike the default automatic variable that is stored in stack. A static variable can be initialized by using keyword static before variable name.
This is useful if we want to isolate pieces of a program to prevent accidental changes in global variables. Static local variables are variables whose value is held in a function call to another.
static int a = 5;
A static variable behaves in a different manner depending upon whether it is a global variable or a local variable. A static global variable is same as an ordinary global variable except that it cannot be accessed by other files in the same program / project even with the use of keyword extern. A static local variable is different from local variable. It is initialized only once no matter how many times that function in which it resides is called. It may be used as a count variable.
The function count () returns the number of times it has been called. See the local int variable is initialized. This boot is only valid for the first time the function is called as a must maintain its value from a call to the other. What the function does is increase in every call and return its value. The best way to understand this is by implementing static local variable.
static int count1 = 0;
int count2 = 0;
printf("\nValue of count1 is %d, Value of count2 is %d", count1, count2);