say, like suppose we have 1.c and 2.c both include 1.h.We have defined count variable in 1.h
You never define a variable in a header file. Let me repeat that: You never define a variable in a header file.
If you do, then every time you include the header you get a anotrher variable. When your build gets to the link step, it will fail is redefinition errors.
What your do is define the variable in a .c file:
To access this variable from another .c file you tell the compiler the variable is defined outside (external to) this file:
-
//another .c file.
-
-
extern int var;
-
-
All the header file does is save you from putting than extern in every .c file. Instead you put the extern in the header and then include the header.