Header files serve as the interface between your program and the libraries supplied by the C compilation system. Because the functions that perform standard I/O, for example, very often use the same definitions and declarations, the system supplies a common interface to the functions in the header file <stdio.h>. By the same token, if you have definitions or declarations that you want to make available to several source files, you can create a header file with any editor, store it in a convenient directory, and include it in your program as described in the first part of this section.
Header files traditionally are designated by the suffix .h, and are brought into a program at compile time. The preprocessor component of the compiler does this because it interprets the #include statement in your program as a directive. The two most commonly used directives are #include and #define. As we have seen, the #include directive is used to call in and process the contents of the named file. The #define directive is used to define the replacement token string for an identifier. For example,
#define NULL 0defines the macro NULL to have the replacement token sequence 0. See ``C and C++ compilation system'' for the complete list of preprocessing directives.
When you use a library function in your program, the manual page will tell you which header file, if any, needs to be included. If a header file is mentioned, it should be included before you use any of the associated functions or declarations in your program. It's generally best to put the #include right at the top of a source file. These are some frequently used header files:
|floating point limits
|other data type limits
|date and time