I have a doubt about the global variable. The global variable is the variable that is declare out side of function
Code:
#include<stdio.h>
int x; // global variable
void foo ()
{
x = 0;
x++;
printf( "x = %d", x);
}
int main()
{
foo();
return 0;
}
My thought is that if I made the variable x a global variable in main.c, can I use it in another file foo.c?
main.c
Code:
#include<stdio.h>
int x; // global variable
int main()
{
foo();
return 0;
}
foo.c
Code:
void foo (){
x = 0;
x++;
printf( "x = %d", x);
}
I think that I can access the x only in main.c
Can we access x from foo.c file ?