C Header Files


A header file contains forward declarations of functions and variables. Every external function will be mentioned in a header file, including libraries that are pre-compiled into object code, and source files required to build the C program.

Standard Header Files

Set of libraries for additional functionality. We place references to these at the start of the source code file that uses one or more functions from that library.

Example: The compiler can compile the source code below, thanks to the #include line, which tells it where the definition of printf can be found.

#include <stdio.h>
void main ( void ) // Entry point function
printf("Hello World"); // Output

User Defined Header Files

When the programmer has functions that provide additional capabilities, then they might want to create a separate source code file to contain these functions.

Example: The quotes surrounding MyOutput.h are required to tell the compiler not to look along the standard library path, but to look in the same path as the source file. Also PrintNicely() function has

#include "MyOutput.h" // My output functions
void main ( void ) // Entry point function
PrintNicely ("Hello World"); // Output

Recommended Books for Learning C Programming

Any Comments about this page

Your name
Extra comments
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.