The preprocessor simply reads the header files and puts them into the translation units where the #include
directive is. If one header file is included in one source file, only that file knows about the declarations in that header file.
You also should know the difference between declarations and definitions. When you declare something, you just tells the compiler that "this thing exists and is of type this-and-that". When you define something, you tell the compiler "this is the thing I declared before".
You can have multiple declarations of the same thing. because they only act as meta-data for the compiler, and are not used outside its translation unit. You can however only have one definition of something. That's why you can't define global variables/functions in header files included in multiple source files.
Also, In this answer I talk about "source files", "header files" and "translation units". Header files are the files you #include
. Source files is the files that does the including (so to speak). And a translation unit is the complete preprocessed source, complete with the source and all included header files, and which is passed on to the actual compiler.