Importance of Header Files

What is the importance of header files?

The main role of header file is it is used to share information among various files.

In brief, if we have several functions say 4 functions named as f1, f2, f3, f4 placed in file say sample.c and if all the functions want to get accessed by each other then all must be placed in the same file sample.c.

In other words, if there is a function say f5 placed in another file say example.c and if the function f1 placed in sample.c wants to access the function f5 placed in example.c, it is not possible.

In order to allow function f1 in sample.c to access function f5 in example.c, add the function definition in the main program from which the function is going to get called.

This process becomes tiring if the program has lot of functions.  If there is a change in arguments in functions, each time programmer has to search for the function definition file and has to make change in the function definition file as well as in the actual function.

In order to avoid above setback and to make the process simple, it is essential to have a header file and place the function declarations in a header file say for instance if the header file is sample.h where function declarations area made the programmer has to include this header file in the source file where the functions are used as

    #include sample.h

In this way if there is any modification in function arguments only the actual function and the definitions defined in the single header file has to be changed.

Editorial Team at Geekinterview is a team of HR and Career Advice members led by Chandra Vennapoosa.

Editorial Team – who has written posts on Online Learning.

Pin It