Thursday 23 February 2012

Header files in C and C++ programming


What are header files ?


Files that are placed at the header portion (before main()) of c program are called the header files.
Normally, the standard header files are having .h as extension which designates a header file. However , the user defined header files may have different extensions.
The header files are used to provide the necessary information in support of the various library functions. Each header file contains declaration for certain related library function. For example, stdio.h is a header file containing declarations for input/output functions. Similarly math.h header file contains declaration for certain mathematical functions.some of the important and commonly used header files are:

stdio.h                  input/output  functions
math.h                  mathematical functions
string.h                 string manipulation functions
malloc.h               memory allocation/deallocation function
stdlib.h                 some standard library function
ctype.h                character manipulation fuction
time.h                  time computing functions
graphics.h            graphical function
dos.h                   functions linking DOS routines.


The header files are entered into the source program via a #include statement. The # include statement is a preprocessor statement and must be written at the beginning of the program.
The stdio.h header file can be included in your source program by writing the following statement
#include<stdio.h>
Observe that the header file stdio.h is enclosed within angle brackets(< >). Alternatively, we can also write the header file within double quotes as

#include”stdio.h”


If we write the header file is enclosed within angle brackets, it means that the compiler will search for the header file in the default include directory. (Note that the include directory is one in whichthe compiler’s installation program  will place the header files).  If the required header file is not found in the current directory during the compillation process, then the compiler searches for it in the include directory. On the other hand,  if we write the header file name within double quotes, the compiler will search for that header file in the current directory only. If the file is not found , it will flag an error message.

No comments:

Post a Comment