Header Files in C

PHPz
Release: 2024-08-30 20:30:10
Original
710 people have browsed it

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.

The above is the detailed content of Header Files in C. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!