I have written following code for extern variable
File Test1.c
File Test2.c
Program output : 1
1. Am I using the extern variable correctly ?
2. Why program output 1 appear even if I remove the extran keyword from File Test2.c ?
3. Why program show error if I am declaring x as local variable ?
File Test1.c
Code:
#include <stdio.h>
int x = 0;
void Func();
int main() {
Func();
printf("%d", x);
return 0;
}
Code:
extern int x;
void Func() {
x++;
}
1. Am I using the extern variable correctly ?
2. Why program output 1 appear even if I remove the extran keyword from File Test2.c ?
3. Why program show error if I am declaring x as local variable ?