"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Header Files in C

Header Files in C

Published on 2024-11-07
Browse:814

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.

Release Statement This article is reproduced at: https://dev.to/sonu_kumar_fe2d7441fff033/header-files-in-c-305 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3