C #include

Description

A header file is any external file whose contents are included into your program by use of the #include preprocessor directive.

For example

#include <stdio.h>

This fetches the standard library header file supporting input/output operations into your program.

Syntax

The general statement for including standard libraries into your program:

#include <standard_library_file_name>

Any library header file name can appear between the angled brackets.

Your own source file

You can include your own source files into your program with a slightly different #include statement.

A typical example might be this:

#include "myfile.h"

Difference


The difference between  
#include <standard_library_file_name>

and

#include "your_own_file_name"

is that

  • The first form will search the default header file directory for the required file,
  • The second form will search the current source directory before the default header file directory is searched.

Note

Header files cannot include implementation of executable code. Header files are for function prototypes and type declarations, not function definitions or initialized global data.

Function body definitions and initialized globals are placed in .c source files.

A file included by an #include directive may also contain another #include directive.





















Home »
  C Language »
    Language Advanced »




File
Function definition
String
Pointer
Structure
Preprocessing