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 :
- #include <filename.h>
- #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.
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 implementational 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 others
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. Do leave your valuable comments.
Also See : extern Keyword
No comments:
Post a Comment