|
|
Static Variables |
|
Have different usage depending on whether the variable is in global scope.
When used with global variables and functions, the variable cannot be accessed outside the file where the variable is declared.
When used with local variables, the variable does not get destroyed when the function returns.
Next time the function is called, the value of the static variable will be the value the last time the function was called.
Cannot be used in function parameter lists
In the following program, the first time the function is called, x has the value of 5, the next time it has the value of 6.
void func () {
static int x = 5;
printf ( "%d\n", x++ );
}
int main (void) {
func();
func();
return(0);
}