Name

#include

Synopsis

The #include directive instructs the preprocessor to insert the contents of a specified file in the program at the point where the #include directive appears.

Syntax:

#include  <filename>
#include  "filename"

If the filename is enclosed in angle brackets, the preprocessor only searches for it in certain directories. These directories are usually named in the environment variable INCLUDE .

If the filename is enclosed in quotation marks, the preprocessor first looks for the file in the current working directory.

The filename may contain a directory path. In this case, the file is only looked for in the specified directory.

The files named in include directives are generally “header” files containing declarations and macro definitions for use in several source files, and have names ending in .h. Such files may in turn contain further #include directives.

In the following example, one file to be included is selected based on the value of a symbolic constant:

#include <stdio.h>
#include "project.h"
#if VERSION == 1
  #define  MYPROJ_H  "version1.h"
#else
  #define  MYPROJ_H  "version2.h"
#endif
#include MYPROJ_H

Get C Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.