answersLogoWhite

0


Best Answer

Headers are primarily used to separate interfaces from implementations in order to provide modularity and organisation of code. Headers typically contain declarations of related data types, classes and functions while corresponding source files contain the implementations or definitions for those types. The only real exceptions are template functions and classes which must be fully-defined within the header.

By separating the interfaces from the implementations, other source files can make use of those interfaces simply by including the appropriate headers. All headers must use header guards to ensure each is only included once in any compilation.

Headers can also include other headers, however this is only necessary if the header requires access to the interface contained therein. For instance, if the header declares a derived class, the base class header must be included as the derived class declaration needs to know the interface details of its base class. Similarly if a class contains an embedded class member, the interface for that member must be known. Pointers and references to types do not require interfaces, thus a forward declaration suffices. However, if a header includes an inline implementation that requires an interface (such as an accessor that returns a type by value, or that invokes a method of a type), the appropriate header for that type must be included.

All types that can be forward declared in a header must be included in the header's corresponding source file.

The one exception to separating interface from implementations is when creating template functions or classes. Templates must be fully-defined thus all implementation details must be available from the header alone. One way of maintaining separation is to have the header include the source file rather than the other way around. However, the inclusion must come after the interface declaration, and the source must not include the header.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

Header files usually have a .h or .hpp file extension (for C and C++ respectively), but not always. Any plain-text file can act as a header file, regardless of its extension.

Header files are generally used to store the prototypes for classes and functions, physically separating their definition from their implementation which is normally contained in another file, the source file, usually with a .c or .cpp file extension. The extension is merely a convention, any extension will do. However, the implementation file must #include the header file.

Header files are also used to provide prototypes for binary files containing the implementations, such as dynamic link library (DLL) files. In order to use the DLL within your program, you must link the binary and #include the header file associated with it.

Where the definition and implementation are combined into a single file, the file is regarded as both a header (which can be #included in other files) and a source file (which can be compiled). Generally, complex implementations are placed in a separate source file, while simpler implementations are contained in the header file itself, usually as inline expanded implementations.

Compilers use the header files included in your application to determine the prototypes employed by the implementations. Without the header files, the compiler would have a hard time working out if you'd called the implementations correctly or not, especially if the implementations were contained in a binary file.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

You don't "call" a header file, you include it using the #include precompiler directive.

There are two ways to include a header:

#include "my_header.h"

#include<my_header.h>

The first assumes that the header resides in the same folder as the file in which the inclusion is declared, or in a sub-folder relative to that folder. E.g., #include "..\my_header.h" specifies that the header resides in file's parent folder. You will typically use this form for user-defined headers.

The second assumes the file exists somewhere in the environment's INCLUDE path. You will typically use this form for all standard library includes.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Any file you include into your program with directive #include

Headers usually have .h extension and contain declarations.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

as u write some functions like

clrscr ()

getch ()

their definition is consist in header files

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What does the header file in c consists of?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How can you create a c program without using header file?

C programs do not require header files. If you want a C program without header files, you can simply not create them. However, you may or may not be able to include your non-header file source files.


How many types in header file in mathh header file in c language?

Look for typedef in it, but I don't think you will find any.


Explain about header files used in c language?

list of header files in c and function prototype associated with each file


What is the header files from random functions?

The header file for random functions ( like rand(), srand() ) is stdlib.h in C and cstdlib in C++.


How do you create a header file and implementation of code in another c file and both should be retrieved by another .c file?

tanga


How can you create a header file in c?

Use a text-editor.


More about hedder file in c?

For start: they are header files.


How do you include a system header file called sysheader.h in a c source file?

There is no system header called share.h, but if there were, it would be: #include &lt;share.h&gt;


A function is declared in C header file When you try to implement in a c source file it is giving error?

The source file must include the header file. Beyond that we can only guess at the problem without seeing the content of the source and header files. Do not post the files here. Such questions are better handled by the many C programming forums available elsewhere on the Internet.


How can you create a headerfile in a c?

Create the header file as a .h file in the same way you create a source file, .c and place it in the same directory as the .c files. To incorporate it, use the... #include "my_header_file.h" ... directive. Note that there are double quotes instead of greater/less signs. This tells the compiler to look first in the source directory.


What is the structure of c prgramming?

A header file , a main part and a body


How do you create an header file in c with example?

Any file can be called a header. Whenever someone uses #include , it's the same as copy/pasting that file in that spot. Typically though, they call it a header if it's included at the beginning of your source.