I saw a program source code in which a variable is defined in a header
file and that header file is included in 2 different C files.When i
compile and link the files no error is being thrown.How is this
possible.I thought it will throw "Variable redefinition Error". Giving
the source code for reference.Pleas e help me out on this...
a.h
-----
int g;
void fun(void);
a.c
-----
#include "a.h"
void main()
{
g = 50;
printf("%d\n",g );
fun();
printf("%d\n",g );
}
b.c
----
#include "a.h"
void fun(void)
{
g = 120;
}
Output is 50...120
Regards
Manu
file and that header file is included in 2 different C files.When i
compile and link the files no error is being thrown.How is this
possible.I thought it will throw "Variable redefinition Error". Giving
the source code for reference.Pleas e help me out on this...
a.h
-----
int g;
void fun(void);
a.c
-----
#include "a.h"
void main()
{
g = 50;
printf("%d\n",g );
fun();
printf("%d\n",g );
}
b.c
----
#include "a.h"
void fun(void)
{
g = 120;
}
Output is 50...120
Regards
Manu
Comment