The #include directive

A preprocessor include directive causes the preprocessor to replace the directive with the contents of the specified file.

Read syntax diagramSkip visual syntax diagram
#include directive syntax

>>-#--include--+-"--+-----------+--file_name--"-+--------------><
               |    '-file_path-'               |   
               '-<--+-----------+--file_name-->-'   
                    '-file_path-'                   

If the file_name is enclosed in double quotation marks, for example:
#include "payroll.h"
it is treated as a user-defined file, and may represent a header or source file.
If the file_name is enclosed in angle brackets, for example:
#include <stdio.h>
it is treated as a system-defined file, and must represent a header file.

The new-line and > characters cannot appear in a file name delimited by < and >. The new-line and " (double quotation marks) characters cannot appear in a file name delimited by " and ", although > can.

The file_path can be an absolute or relative path. If the double quotation marks are used, and file_path is a relative path, or is not specified, the preprocessor adds the directory of the including file to the list of paths to be searched for the included file. If the double angle brackets are used, and file_path is a relative path, or is not specified, the preprocessor does not add the directory of the including file to the list of paths to be searched for the included file.

The preprocessor resolves macros contained in an #include directive. After macro replacement, the resulting token sequence consists of a file name enclosed in either double quotation marks or the characters < and >. For example:
#define MONTH <july.h>
#include MONTH
Declarations that are used by several files can be placed in one file and included with #include in each file that uses them. For example, the following file defs.h contains several definitions and an inclusion of an additional file of declarations:
/* defs.h */
#define TRUE 1
#define FALSE 0
#define BUFFERSIZE 512
#define MAX_ROW 66
#define MAX_COLUMN 80
extern int hour;
extern int min;
extern int sec;
#include "mydefs.h"
You can embed the definitions that appear in defs.h with the following directive:
#include "defs.h"
In the following example, a #define combines several preprocessor macros to define a macro that represents the name of the C standard I/O header file. A #include makes the header file available to the program.
#define C_IO_HEADER <stdio.h>

/* The following is equivalent to:
 *   #include <stdio.h>
 */

#include C_IO_HEADER

C++11 In C++11, the changes to header and include file names in the C99 preprocessor are adopted to provide a common preprocessor interface for C and C++ compilers. The first character of a header file name in an #include directive must not be a digit in C++11. For more information, see C99 preprocessor features adopted in C++11 (C++11).