With static
in C
one can keep a stack
variable around, even after the creating function exists.
In this case however,
void static_func() {
static int var = 1;
var += 1;
}
I can access var
outside of the static_func()
and return its value. Let's assume static_func()
is called three times in the main()
, then the value of var
is 3.
However, it is set to 1
every time the function is executed. Why do I still get the value 3?!