Welcome to the first part of the Gentle Introduction to C series. This series will aim to give you a brief introduction to C language.
In this part we will look at one of the most important take-for-granted tool in C, namely the header files.



Header Files

A header file is a file that contains macros and function declarations. These header files are saved using a ‘.h’ extension and can easily be included in a file using the #include pre-processor directive.

C provides with two ways to include a header file :

  1. #include <filename.h>
  2. #include “filename.h”

However it is a common convention to use the former for standard files and the latter for user - defined files.

Example :

#include <stdio.h> - Includes the standard stdio header file in the program

#include "hello.h" - Includes the user-defined hello header file in the program

Including a header file copies all the header file’s contents to file during pre-processing time. And rightly so, header files should not be included more than once as it will copy the contents more than once, which will result in multi declaration(s) error during compile time.


Interesting Fact : Original Windows kernel was written in a dialect of C language along with an assembly language. Even now also some OS kernels are written in C.

Header file provides a way to link to standard file(s) which usually contains basic yet important functions (like input and output). The header file makes the code look cleaner and less cumbersome, hence enhancing readability. It also provides the user with optimized functions with very subtle implementation details which could help to reduce the running time of the program.

Examples of  Standard header files :

stdio.h - Contains standard I/O operations

stdlib.h - General purpose header file containing functions like memory allocation, process control, conversions.

and many more.

Lastly, in my view, the header files are C’s way of implementing modern day concepts like modularity in the code.

Thank you for reading.