What is the importance of header files?

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

To put it 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 each other 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. For this what we can do is add the function definition in the main program from which the function is going to get called. But this will make the process tiring if the program has lot of functions because 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. These will make the process tiring.

To avoid all this and to make the process simple what one can do is 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 ahs to include this header file in the source file where the functions are used as

#include sample.h

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

Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 1 of 1 Answers


  • Oct 12th, 2006

we r using numerous predefined c functions like,printfsqrtscanfgetchmallocFILENULLif strcmp etc, these functions coding,prototype,execution are defined and categorized and stored in different files while we user while programing we use this functions which makes our programming very easy.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions