A set of pre defined library functions and macro definitions are contained in C header files.

The extension .h is used for C header files.

For including a header file in C program the #include is used before the name of the file( that the programmer wants to include). After including a header file we can use its contents as per our requirement.

Header files can be of two types
Pre existing header files : These are those files which are already defined in system and all we need is to import them to use its contents.
User defined header files : When a user defines a header file then it is called user defined header file. A user can define multiple header files.

Note : For including both pre existing and user defined header file we need to use #include preprocessor in our program. This preprocessor directs the compiler to include all the necessary data type and method definitions before the actual compilation of the program.

Syntax :
There are two ways in which you can use header files :
1. #include <filename.h>
2. #include “filename.h”

You can use either of the two ways mentioned above. But remember that we can’t include header same file two times in the program.

#include <stdio.h>
int calculate_age( int y)
const int currentyear = 2020;
return currentyear – y;
int main( )
printf( “% u” , calculate_age(1998));

The stdio.h files contains printf function definition which is the standard output function of the C programming language.
In case one forgot to include stdio.h file in above program then an error will occur while compiling the program and desired output wouldn’t be obtained.

Other important header files used in C
language are :
console.h : To import console input/output functions.
math.h : To import mathematical functions in program.
stdlib.h : To import general utility functions in program.
ctype.h : To import character handling type functions.
string.h : To import string type functions.
float.h : To import limits of float data type.
time.h : To import date and time functions.

Leave a Reply

Your email address will not be published. Required fields are marked *