Originally Posted by
laserlight
Both have static storage duration, and typically what makes a static local useful
Local static
Code:
#include<stdio.h> int fun()
{
static int a = 0;
a = a + 1;
return a;
}
int main()
{
printf("%d ", fun());
printf("%d ", fun());
printf("%d ", fun());
printf("%d ", fun());
return 0;
}
Global static
Code:
#include<stdio.h>
static int a = 0;
int fun()
{
a = a + 1;
return a;
}
int main()
{
printf("%d ", fun());
printf("%d ", fun());
printf("%d ", fun());
printf("%d ", fun());
return 0;
}
Both are the codes gives same output
I do not understand when do we use static global and local static in code