I want to know what is the difference between declaring a static variable locally and globally, because in below example.
If results do not impact, then why we have two scopes for static?
#include <stdio.h>
static int y = 0;
int main()
{
int x;
x = func_call();
printf("x is %d\n",x);
x = func_call();
printf("x is %d\n",x);
return x;
}
int func_call()
{
y++;
return y;
}
#include <stdio.h>
int main()
{
int x;
x = func_call();
printf("x is %d\n",x);
x = func_call();
printf("x is %d\n",x);
return x;
}
int func_call()
{
static int y = 0;
y++;
return y;
}