I learned some C and came across an explanation for static variables. They showed this code:
#include<stdio.h>
int fun()
{
static int count = 0;
count++;
return count;
}
int main()
{
printf("%d ", fun());
printf("%d ", fun());
return 0;
}
I can't understand why calling the function twice is fine, because the line
static int count = 0;
actually runs twice... I can't understand how is that possible... Can you actually declare it twice or does the compiler just ignore it the second time?