below is my code:
//main.c
int x = 9;
int f()
{
static int x = 0;
x += 1;
return x;
}
int main()
{
printf("Value is %d", f());
return 0;
}
my questions are:
Q1-inside f()
, there is a local static varaible x
defined, and there is gloabal variable also called x
, the program does compile, but isn't it a conflict to the compiler and linker?
Q2-when I run it, the output is 1, which means that the x
in x += 1;
is the local static varaible x
, not the gloabal variable x
.But I could have mean "increment the global variable x", how can I do it?