/*main.c*/
#include<stdio.h>
extern void func(void);
main()
{
extern int i;
printf("i in main %d\n",i);
printf("Call to func before modifying i in main...\n");
func();
i=66;
printf("Call to func after modifying i in main to 66..\n");
func();
getchar();
}
/*file1.c*/
char i=65;
void func(void)
{
printf("i in func %c\n",i);
}
OUTPUT:
i in main 65
Call to func before modifying i in main...
i in func A
Call to func after modifying i in main to 66..
i in func B
Question:
Why 'i' in main and file1 referring to same object? Why doesnt it give a link error saying undefined reference to 'i' as the types are conflicting though names are same.
If char i in were present in main itself, one would get complile error saying conflicting names.
Looking for a right explanation.
Thanks
Swapna