CThe #include Directive

The #include Directive

#include is a preprocessor instruction that tells the preprocessor: find this file, and paste its entire text content in, right at this exact spot, before compilation continues.

Angle Brackets vs Quotes

Syntax

Example

Search behavior

Angle brackets

#include <stdio.h>

Searches the compiler's standard system include paths — used for standard library and third-party headers

Double quotes

#include "myheader.h"

Searches relative to the current file's directory first, then falls back to the system include paths — used for your own project headers

C
#include <stdio.h>     /* standard library header, angle brackets */
#include <stdlib.h>
#include "mathutils.h"  /* local project header, double quotes */

int main(void)
{
    printf("2 + 3 = %d\n", add(2, 3));
    return 0;
}
What Actually Happens at #include

There is no special magic to #include — it is a literal copy-and-paste operation performed by the preprocessor. The contents of the target file replace the #include line entirely, as if you had typed the header's text directly into your .c file at that point.

Why headers should mostly hold declarations, not definitions
Because `#include` performs a textual paste, including the same header from two different `.c` files means that header's content gets compiled twice — once per file. If the header contains a full function or global variable **definition** (a function body, or `int total = 0;`), both resulting object files will contain that same symbol, and the linker will reject the program with a multiple-definition error. Headers should generally contain only **declarations** (function prototypes, `extern` variables, type definitions, macros) — things that describe a symbol without allocating storage or generating code for it.
Standard Headers Are Just Text Too

Running gcc -E on a file that includes <stdio.h> shows hundreds of lines of declarations pasted in verbatim — function prototypes for printf, scanf, fopen, type definitions like FILE, and macro constants like EOF. The standard library headers are ordinary text files that go through exactly the same #include mechanism as your own project headers.

  • Standard library headers → angle brackets: <stdio.h>, <stdlib.h>, <string.h>

  • Your own project headers → double quotes: "config.h", "mathutils.h"

  • The next two pages cover writing your own header files and protecting them from being pasted in more than once