Skip to main content

#include Directive in C

The #include directive tells the preprocessor to copy the contents of another file into the current source file before compilation. This is how you bring standard library functions and your own header files into a program.

Syntax

For standard (system) headers — use angle brackets:
For your own (user-defined) headers — use double quotes:
The difference: angle brackets search the system include directories; double quotes search the current directory first, then system directories.

Common Standard Header Files


Example: Including Multiple Headers


Creating Your Own Header File

mymath.h:
mymath.c:
main.c:

Include Guards

Header files use include guards to prevent being included more than once (which would cause redefinition errors):
Or the modern equivalent (most compilers support it):