what is a header file?
Answers
Answered by
1
A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.
Answered by
0
In both C and C++ programming languages, there is a distinction between:
a declaration or prototype that gives information about a symbol (name of a variable, function, data type, etc.) that enables its usage to be type-checked and for code to reference the symbol.
a definition that reserves memory for the symbol and provides its implementation (e.g. for a function, that would be the sequence of instructions to execute when that symbol is invoked).
A header file is a file that contains declarations (whereas a source file contains definitions)*. Header files almost always end in the suffix “.h” by convention; however, some people use “.hpp” (for C++ headers), and in theory, any naming would be okay (it is only convention that dictates “.h”).
The role of a header file from the perspective of a library writer is to expose the subset of definitions to library users that the library users should be permitted to use and depend on. The role of a header with respect to a library user is to declare all of the symbols provided by the library dependency. Headers make it possible for the user of a library to make use of the library's functionality without necessarily having access to the source code for the library. In other words, the header constitutes an Application Programmer Interface (API), as it specifies a metaphorical “contract” between the producer and consumer of a piece of functionality so that the two can interpretate, but it does not include the implementation that provides the functionality*.
*NOTE: In C++, there is an exception to this rule in that “inline” functions and templates have the definition provided in the header file.
a declaration or prototype that gives information about a symbol (name of a variable, function, data type, etc.) that enables its usage to be type-checked and for code to reference the symbol.
a definition that reserves memory for the symbol and provides its implementation (e.g. for a function, that would be the sequence of instructions to execute when that symbol is invoked).
A header file is a file that contains declarations (whereas a source file contains definitions)*. Header files almost always end in the suffix “.h” by convention; however, some people use “.hpp” (for C++ headers), and in theory, any naming would be okay (it is only convention that dictates “.h”).
The role of a header file from the perspective of a library writer is to expose the subset of definitions to library users that the library users should be permitted to use and depend on. The role of a header with respect to a library user is to declare all of the symbols provided by the library dependency. Headers make it possible for the user of a library to make use of the library's functionality without necessarily having access to the source code for the library. In other words, the header constitutes an Application Programmer Interface (API), as it specifies a metaphorical “contract” between the producer and consumer of a piece of functionality so that the two can interpretate, but it does not include the implementation that provides the functionality*.
*NOTE: In C++, there is an exception to this rule in that “inline” functions and templates have the definition provided in the header file.
Similar questions
Math,
7 months ago
Computer Science,
7 months ago
Computer Science,
7 months ago
Biology,
1 year ago
English,
1 year ago