Keil Logo

How #include Works

The #include directive tells the C preprocessor to include the contents of the file specified in the input stream to the compiler and then continue with the rest of the original file.

For example, the header file, file.h contains the following:

char *func (void);

The program file, myprog.c includes this header file:

#include "file.h"

void main (void)
{
while (1)
  {
  printf (func());
  }
}

The output generated by the proprocessor is:

char *func (void);

void main (void)
{
while (1)
  {
  printf (func());
  }
}

Header files typically contain variable and function declarations along with macro definitions. But, they are not limited to only those. A header file may contain any valid C program fragment. However, this practice is error-prone, very confusing, and not at all recommended.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.