Below is my code:
//main.c
int f()
{
static int x = 0;
x += 1;
return x;
}
int main()
{
f();
printf("%d", f());
}
and the output is 2.
I know that static variable will persist state, but since I called f() twice, each time x is set to 0 first (static int x = 0; ), then plus 1, then the output should be 1 regardless of how many times I call f()?