Header File In C Programming language

Posted by Tushar Bedekar
As We all know that in the C programming language we use to include the header files before staring the programming further. so lets view today what these header files mean to us.

As in the old programming IDE`s such as turbo c etc. we use to write as below
                          #include<stdio.h> 
#include<conio.h>        
These two are the basic header files that we usually include.There can be also different types of the header files such as<math.h>,<string.h>,<graphic.h>,<string.h>,user defined header files and many more depending on the type of the requirement in the program me written.now before moving further lets us first know what s header file.

What is 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 pre-processing 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.

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.

Include Operation:-

The #include directive works by directing the C preprocessor to scan the specified file as input before continuing with the rest of the current source file. The output from the preprocessor contains the output already generated, followed by the output resulting from the included file, followed by the output that comes from the text after the #include directive. For example, if you have a header file header.h as follows:
char *test (void);
and a main program called program.c that uses the header file, like this:
int x;
#include "header.h"

int main (void)
{
   puts (test ());
}
the compiler will see the same token stream as it would if program.c read
int x;
char *test (void);

int main (void)
{
   puts (test ());
}
The Next Discussion Will Be on Introduction to a various types of header files in brief. so stay connected with us.Readers One Important note for you (if any one wants to share there articles with us on any topic please click the link belowWrite for Us
back to top