Hi forum
I do not understand difference between between global and static global variable. I know global variable can be access anywhere in program where as local variable is only accessible in the function and static is storage class
In my program, x is global variable and y is static global variable I do not understand when I will need a static variable because I don't understand much difference between auto global and static global variable. they both will exit until program run. They both are accessible anywhere in program
I do not understand difference between between global and static global variable. I know global variable can be access anywhere in program where as local variable is only accessible in the function and static is storage class
C:
#include <stdio.h>
int x = 0;
static int y= 0;
void foo()
{
static int z = 0;
printf("%d \n", z);
}
int main()
{
foo();
foo();
printf("%d \n", x);
printf("%d \n", y);
return 0;
}