HOW TO CREATE YOUR OWN HEADER FILE IN C LANGUAGE

Header File


A header file is a file with extension .h which contains C function declarations and macro definitions and to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that come with your compiler.
You request the use of a header file in your program by including it, with the C preprocessing directive#include like you have seen inclusion of stdio.h header file, which comes along with your compiler.
Including a header file is equal to copying the content of the header file but we do not do it because it will be very much error-prone and it is not a good idea to copy the content of header file in the source files, specially if we have multiple source file comprising our program.
A simple practice in C or C++ programs is that we keep all the constants, macros, system wide global variables, and function prototypes in header files and include that header file wherever it is required.

Include Syntax

Both user and system header files are included using the preprocessing directive #include. It has following two forms:
#include <file>
This form is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option while compiling your source code.
#include "file"
This form is used for header files of your own program. It searches for a file named file in the directory containing the current file. You can prepend directories to this list with the -I option while compiling your source code.

Need of creating of your own header file ?

when you write a programme the some part of the code is repeated again and again so the same code is typing again and again in diffrent programme and due to this your time is waste and your programme is also lengthi and the user is also take more time to understand the programme...

For example

  •  If you need perform addition in your diffrent programme so dont need to write the same code again and again. You just simply create your header file and use it.

Steps for creating header file

Write a programme for addition
programme-1



      2. save your programme with .h extension.




3. Now if you want to perform addition in your programme so firstly add header file
#include"addition.h"

4. And then where you want to perform addition you just call simply a function addition.

addition();

Programme-2

 4. Output of this programme -:



Now some of you think, in programme-2 we don't include any header file (like stdio.h,conio.h) accept "addition.h".
we dont need need to include these hearder file because in addition.h programme we already add these header file so we dont need to again add these header file in  programme -2..

THANK YOU