Hi,
I have 3 files as below
a.c:
Code:
int x(int a, int b)
{
return a + b;
}
b.c
Code:
extern int x(int,int);
int main()
{
int res;
res = add(2,3);
printf("res= %d",res);
return 0;
}
In the file b.c, as function add is defined in a.c, I have used extern declaration for the prototype of the function.
But instead of this, if I use a header file lets say a.h which contains the prototype of the function x as below
a.h
then if I include this a.h in b.c, then do I need not place the extern declaration again??
extern declaration tells the compiler that the function x is defined externally in another file.
But if I include the a.h simply in b.c, as it copies the contents of the a.h in b.c, then there will be no extern. So how the compiler knows that function x is defined externally somewhere??