Header Files in C Language

Header Files in C also known as include directive used to copy the contents of a file to be inserted into another file(original file/source code) and often used to define the physical layout of program data, pieces of procedural code and to reuse the code.

Header Files in C Language

Header Files in C contains function declarations and macro definitions to be used latter. There are two types of header files in c language, one that comes with c compiler and another that the programmer writes. to use a header files in c program you have to use the C preprocessing directive #include. 

when you use header files in c language then the content of that header file is copied to your source code file but it doesn't mean that you should try to copy the content of header file instead of using #include directive because it it will be error-prone and complex when you are working on a project.

How to Use Header files in C language ?


To use Header files in a C program you have to use the C preprocessing directive #include. C preprocessing directive #include can be used in two different forms:

1.For System Header Files

#include<filename>
Above Syntex in C program searches for the specified file name in a standard system directories and then searches in local or project-specific paths. the project-specific paths can be specified on the command line or in an environment variable.

2.For Header files in project-specific paths

#include "filename"
The form of #include directive does not search in a standard system directory, only searching in local or project-specific paths.

Importance Of Header Files in C Language


Header files plays an important role in c language and provide us an important feature of code re-usability. for example we have two functions first function1 in file1.c and second function2 in file2.c, now if function1 in file1 wants to use function2 from file2 then its not possible. to solve this problem header files in c language used. if a function is in a header file then other file can use that function using header file.

For an example printf function to print output and scanf function to get input defined in a header file named stdio.h, so we can simply use #include<stdio.h> in c program to use printf and scanf.

Function in C standard Library grouped into different header files such as printf and scanf in stdio.h, sqrt(to Calculate Square Root), pow(to Calculate Power), log(to calculate Natural Logarithm) in math.h, strlen(to Calculate length of a string), strrev(to reverse a string) etc.    

SHARE THIS
Previous Post
Next Post