## Purpose?

• To hold declarations for other files to use.
• Typically only contain declarations, do not define how something is implemented.

• Standard libary function is implemented in the C++ runtime support library, which is automatically linked into the program during the link phase.

• We need a forward declaration so that the compiler would know about the function (even it is implemented in the another file) when compiling.
• However, writing forward declarations for every function that lives in another file can is tedious.
• A header file only has to be written once, and it can be included in as many files as needed.

• Header guards prevent a given header file from being included more than once in the same file.
#ifndef ADD_H   // can be any unique name

#endif


## How Compiler work with header files?

When the compiler compiles the #include "some_header.h", It simply copies the contents of some_header.h into the current file at that point. Consequently, program will compile and link correctly.

## <header.h> vs "header.h"

• Angled brackets(<>): compiler looks for the header in the system directories.

• Double-quotes(""): compiler looks for the header file in the current directory containing the source code. If not found, it will check any other include paths specified in compiler/IDE settings. That failing, it will fall back to checking the system directories.

## Best practices

• Do not define variables in header files unless they are constants. Header files should generally only be used for declarations.

• Do not define functions in header files.

• Each header file should have a specific job, and be as independent as possible. For example, you might put all your declarations related to functionality A in A.h and all your declarations related to functionality B in B.h. That way if you only care about A later, you can just include A.h and not get any of the stuff related to B.