A static variable holds the value the last time the function was called. The variable was only initialized once the first time the function is called. Static local varriables are stored in the Global Data segment, not on the stack.
Review this example:
Code:
#include <stdio.h>
void test(void);
int main(void)
{
// First call
test();
// Second call after increment
test();
// Third test
test();
return 0;
}
void test(void)
{
static int val = 10;
printf("Current value of val: %d\n", val);
val++;
}
Output:
Code:
Current value of val: 10
Current value of val: 11
Current value of val: 12