DEV Community

SONU KUMAR
SONU KUMAR

Posted on

Header Files in C

What is a Header File

A header file in C is a file with a '.h' extension that contains declarations for functions, macros, constants and sometimes data types that can be shared across multiple source files.

Preprocessor Directive

Preprocessor Directive is a line in a program that is not a programming statement but actually a command for preprocessor.
For Example:-
#inlude
#define
In this command # is a preprocessor and include is a macro.

Types of Header Files

There are mainly two types of Header files
1. predefined Header Files
These are the type of header files provided by C standard library which contain declaration for inbuilt functions.
2. User-defined Header Files
These are the type of Header files that a programmer can create and use in there specific projects. Including declarations for functions, macros, constants, and custom data types.

Ways to declare Header Files

There are Mainly 2 ways to declare header files

  1. using angle brackets <> angle brackets are typically used for declaring standard library header files. Because when we denote a header file using angle brackets the preprocessor searches that specific header file inside the bin file or binary file of the C language system directories.
  2. using Double Quotes"" When we need to declare a user defined header file we have to use double quotes instead of angle brackets. The Difference is that the preprocessor will first search for that header file in the local folder from where the c language file is created and if the file will not be found it will then search in the bin file directives.

How to create a use defined header file

For creating a user defined Header file, just create a file with .h file type and some functions inside that file and save it in either your local folder or c language system directories.
To call that header file use the preprocessor directive #include and then name of the header file in double quotes.
And then You can use your own functions from your own header file without creating it inside that program.

Top comments (0)