#### Chapter 5

The file which consists of macro definitions and C-function declarations is called as header file.

• The extension for header files in C is .h
• ‘.h’ extension file can be used by many of the source file programs written the programmerÂ before the source files are compiled.
• The header files can be used anywhere in the source files by using pre-processor directive #include, in which #symbol implies that the declared statement is pre-processor pointing to a particular file but not normal C-language statement.
• The header files helps in saving the time and complexity in finding a specific file.

Here, theÂ doubt is that, instead of declaring the header file, just copy and paste the statements. But that process is not suggested because itÂ results in errors.

Â
Built-in header files are given within angular braces < >.

#include<file_name>
The file name given is searched in the group of system directories and this is referred as search path.These are only readable filesÂ and writing data is not possible in built-inÂ files.There are many header files in compiler.

Some of the header files in C-standard libraries are:Â

Name Description
stdio.h Input/output functions
conio.h Console input/output
stdlib.h General Utility functions
string.h String functions
math.h Mathematics functions
stdarg.h Variable Argument list functions
signal.h Signal Handling functions
setjmp.h Non-local jump functions
ctype.h Character handling functions
locale.h Localization functions
time.h Date and Time functions
assert.h Diagnostics functions
stdbool.h and stddef.h Boolean data type functions, useful types and Macro definitions

Till now, only single program with .c extension was seen. But,Â inÂ real time projects, there will beÂ multiple .c files with functions spread over all these files.
User-definedÂ header files are representedÂ within double qoutes (” “) and are given by the user.

User-definedÂ header files are mostly used when doing a project. The programs under source files are stored with ‘.c’ extension and the source file may contain many programs with ‘.c’ extensions. All these .c extension files are compiled and linked to form a single .exe extension file such that all the files included uses the header files.

#include"file_name.h"
For example, create a file with .h (say splessons.h) extension and write the following code:

int Add(int a, int b)
{
return a+b;
}
int sub(int a,int b)
{
return a-b;
}

Now create a file with ‘.c’ (say itoolsinfo.c) extension and write the following code:

#include<stdio.h>
#include"splessons.h"
int main()
{
int x,y,sum;
x=1;
y=2;
printf(%d", sum);
return 0;
}

In the above program, there is no need to declare that x and y are integer variables in the calling function as already statedÂ that the variables are integers using header files.In this way, the user-defined header files are used.

There is also an other case to include the header files multiple times which will result in an error. To avoid this, include the declarations of header file in #ifndef, #define and #endif.

For example:

#ifndef splessons
int Sub(int a, int b)
#define splessons
#endif

By using the above syntax in the header file, the entire contents get skipped as the header files are already defined.

## Summary

• Header files in C has extension “.h”.
• Included in the program using pre-processor directive “#include”