Header File in C
A file header is a file with the .h format containing function declarations and macro definitions and can be shared across multiple source files. There are two types of file headers: the file that the programmer writes and the file that comes with your compiler.
You require using the file Header in the program by adding it to the program, with the #include preprocessor character as you add stdio.h to the Header file, it will accompany your compiler.
Including the Header file is equivalent to copying the Header file's content, but you don't need to do it, just #include, your code will be more compact and still use the content of the Header file.
In fact C and C ++ programs we store most constants and macros and global variables and function prototypes in the Header files and include these files when you need to use them.
Syntax include in C
Both the user file and the system header are included using the #include preprocessor instruction. Here are 2 types:
chứa
This format is used for system files . It will find the file with the file name in the list of system directories.
include "file"
This format is used for files in your program. It will search for files with the file name in the same directory as the current file .
Include activities
The #include directive works by directing the preprocessor in the C language to scan certain files to add to the current file before starting with the existing source code. For example, if you have a Header file as header.h as follows:
char * test (void);
and the main program calls program.c to use the File header, like:
int x;
#include "header.h" int main (void)
{
puts (test ());
}
and the compiler will see the same token stream, when the program.c program reads as follows:
int x;
char * test (void); int main (void)
{
puts (test ());
}
Once-Only Header
If the file header is included twice, the compiler will report an error and print an error. The standard way to avoid this case is to use conditional expressions as follows:
ifndef HEADER_FILE
#define HEADER_FILEthe entire header file file # endif
In case it is already included, the above program will not include it again.
Include with the conditions
Sometimes you need to choose one of the headers to include in the program, you must have the operating system configuration parameter to use. You can do this with a range of conditions as follows:
if SYSTEM_1
# include "system_1.h"
#elif SYSTEM_2
# include "system_2.h"
#elif SYSTEM_3
.
#endif
But when this number of conditions is many, it becomes tedious, instead the preprocessor provides the ability to use a macro for the Header name. This is called Conditional Include . Instead of writing a Header name as the direct parameter of #include , you simply put a macro name there instead of it:
define SYSTEM_H "system_1.h"
.
#include SYSTEM_H
SYSTEM_H will be expanded, and the preprocessor will search for system_1.h if #include has been written that way initially. SYSTEM_H can be defined by the file you create with -D option.
According to Tutorialspoint
Previous article: The preprocessor in C
Next lesson: Press type in C
You should read it
- Microsoft Word: How to create page title (Header) and footer (Footer)
- How to Add a Header in Powerpoint
- How to insert Header, Footer in Google Docs
- How to lock Header, Footer in Word
- How to create different Header, Footer on Word
- How to fix 0x00000019: BAD POOL HEADER on Windows
- How to create a page header (Header) and footer (Footer) in Word
- How to insert Header and Footer on PowerPoint when printing
May be interested
- How to delete Header and Footer in Wordword header and footer are inserting content at the top and bottom of the page. so how to delete header and footer in word?
- How to insert underlined Header and Footer Excelafter inserting header and footer in excel, we can add underline under header and footer to increase the professionalism and aesthetics of the content.
- Create Header and Footer for text page in Wordintroduce how to create a header and footer for a text page in word. to create borders for a text page in word 2013 there are 2 basic ways as follows: 1. create header, footer on all pages are the same. step 1: go to insert - header & footer - header -
- What is HTTP Security Header? How to use HTTP Security Headerwhat is x-frame-options? do you know what http security header is? what do they mean in web programming? let's find out with tipsmake.com.com!
- How to create Header and Footer in Wordto increase the professionalism of creating text, the following tipsmake.com introduces you to how to create header and footer in word.
- How to insert images into Header, Footer on Wordinserting header, footer on word in addition to writing text content, you can insert images.
- How to Open an EML Format Fileeml is a file format for outlook and outlook express developed by microsoft. an eml file is an archived email that retains the original html header and formatting. most mail browsers support eml files, but if you don't have a mail browser installed or are on a mobile device, there are ways to help you open this file type.
- Create header and footer in Excelteach you how to create headers and footers in excel. to create the header, the footer follows these steps: step 1: go to page layout - page setup tab - click on the arrow below: step 2: a dialog box appears - click the header tab /
- Protect Header and Footer in Wordif you want users to be able to edit the text of word documents but cannot change important information such as author names ... recorded in the header or footer of the text, please follow this article.
- The simplest way to fix Header loss error in Wordthe header missing error in word is making you angry because you don't know how to handle it? tipsmake has a few suggestions available