C Header Files

The standard library functions or C library are inbuilt c functions whose prototype and data definition are provided in the header files.

Each header file can contain more than one function declarations, data type definitions, and macros. Header files have .h extension and are included with the C preprocessor directive #include.

Syntax

The #include syntax has two variations. The first variation uses <file> syntax which means the preprocessor searches for the header file in pre-designated directories such as the include directory. This syntax is used for including the inbuilt C functions.

#include<stdio.h>

The second variation uses "file" syntax which means the preprocessor first searches in the current working directory and if not found, searches in the pre-defined directory. This syntax is used by the programmers to define their own functions.

#include"Header.h"

Header files may sometimes be present inside a directory rather than the current working directory. To include those files you will have to use a folder structure.

#include"Directory/Header.h"

How Header Files Look?

Header files look similar to normal C files. Once a header file is included into a code, the entire body of the header file is added to the code to generate an object code. A good header file will not contain any function definition or any kind of data allocation.

/* Include Directives */
#include"Header.h"
#include<time.h>

/* Prototypes */
int add(int,int);
int sub(int,int);

We will discuss header files in more detail in the chapter Preprocessor and Macros.


Trending

C Programming

Remember to follow community guidelines and don't go off topic.