Reputation: 57
//FILE1.c
#include<stdio.h>
#include<conio.h>
#include "FILE2.c"
main()
{
printf("%d",i);
getch();
}
//FILE2.c
static int i=5;
Here I'm getting output 5
. Why so? It should be an error, isn't it?
Upvotes: 2
Views: 63
Reputation: 122373
Because you included the source file "FILE2.c"
(which is not recommended). The preprocessor simply replace the line #include "FILE2.c"
with the contents of "FILE2.c"
.
So there is a variable i
in the file FILE2.c
which you have known, but also another variable i
in the file FILE1.c
. Their scope is within their own file(to be precise, their own translation unit).
You should only include header files in C.
Upvotes: 5