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?!
staticand static variables mean something different.1every time the function is executed." Why? Because your compiler contains a bug?stack? This is no keyword in C, nor does C require a stack. And typical implementations which use a stack don't storestaticvariables (which are a subset of static variables) on the stack.rm -f $YOUR_COMPILER_BINARY_WITH_PATH. And(1 + 3 * 1) == 4, not3.