answersLogoWhite

0


Best Answer

A header file is used to define constants, variables, macro's and functions that may be common to several applications. When a system consists of multiple applications that all access the same data it becomes essential that each application uses identical definitions and it is safer for all of those applications to use the same methods to read that data. updating data should only be performed by a single function, from a single application, but reading data can be safely performed by using the common defintions found in header files. you use header files in the programming language C to declare struct's functions and other things that could be usefull for your program.. it makes thing's simpler and easy to use...

User Avatar

Wiki User

18y ago
This answer is:
User Avatar
User Avatar

Jaaiz Ahamed

Lvl 1
1y ago
This answer is very big we cant understand and read
More answers
User Avatar

Wiki User

14y ago

To write a header file, you need a plain text editor. Word processors won't do. If you are under windows, use notepad; if you are under Mac, use TextEdit; if you are under GNU/Linux or other Unix derived (including Mac OS X), you can invoke command line editor nano, vim or emacs, in which case I recommend,reading a manual on how to use those or use a graphical text editor.

The function of the header file is to "set things up" and help you keep the code clean when programming in C.

Usually, a header file contains only definitions and preprocessor directives.

Example of a header file:

//file: myheader.h
#ifndef TRUE
#define TRUE 1;
#endif

In that header file, or in any source file that includes that header file, when you type TRUE it will be as if you typed 1. You can use it for anything, such as:

int foo = TRUE;
int bar = foo + TRUE;

Other preprocessor directives include:


Anyone who does further research, please improve this.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Header files are the placeholder of commonly used function which are frequently used during the execution of a program.

Thus creating header file you are able to globally define the advantage of function available in header file.

Header file are generally tag with your compiler, or these are predefine.

But you can also create a header file which contains a number of function which are commonly ans frequently used in your program. Thus creating header file, you are able to used the strength of structural language. and modularity..

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Header files have many uses but, primarily, they are used to modularise your code and speed up compile times. If you were to write all your code in just one source file (a CPP file), then every time you compiled that code you would have to recompile the entire file. For trivial programs this is hardly a problem as your program will probably compile in a matter of seconds. But for larger projects that might take several minutes to compile it quickly becomes a major headache when attempting to fix runtime bugs. Imagine making a minor change to your code and then waiting 30 minutes for your code to compile before you could actually test the effects. In a typical 8-hour working day, you'd be able to test 16 changes at most.

To speed up compile times you must divide your code into two or more translation units. Only those units that are affected by any changes to the source code need to be recompiled. Thus it pays to organise your functions and classes, keeping each distinct class in a separate file and grouping functions by type. It also pays to separate interfaces from implementations, thus header files should be used to contain declarations while the implementations are defined in separate source files.

By modularising your code you not only speed up compile times but make it much easier to re-use components. That is, if you have several modules that are dependant upon another module, you simply need to include the appropriate header for that module. Taking it a step further, that same module can also be re-used in other projects, either by including the module in those projects or by creating a library from the module. The more code you write the more likely you are to create re-usable components, thus it pays to plan ahead and separate your code by function or class to make it easier to re-use those components. Without modularisation you would be forced to copy/paste code, thus introducing duplicate code and increasing code maintenance. With modularisation, the code is in one place and can be more easily maintained, which in turn automatically updates all of the module's dependencies.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

To provide forward declarations of identifiers, types and functions that are defined elsewhere, such as a source file. The source file must include the header file, as must all other files that use the types declared in the header file.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Header files contain definition of functions which are not part of c itself, for instance, people very often using cin, cout, endl which are defined in iostream.h and so on.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

You can include them into your source code with the #include instruction.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

It is not necessary. Very short and simple programs may work without any header files.

This answer is:
User Avatar

Add your answer:

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

How can you create a header file in c?

Use a text-editor.


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 <share.h>


Which directories should be entered for graphics code in c?

use grphics.h header file


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.


How do you use cosine in c language?

Include the header file math.h and use the function acos(d)


How is possible to addition of two number without including header file in C language?

You do not need a header file to add two numbers in C. You do need the header files if you want to use the run-time library, which includes the ability to format and display the result.


How do you include classes and structures in header files in c plus plus?

Classes and structures can be put in a header file the same way you would use them in a main program; the only difference is that they are placed in a separate file, called a header file. Then, after creating a new file, include that new file with the definition by the use of the preprocessor #include statement.


Why you use header files in c?

the use of header files is to add functionality. Header files are basically saying put code in that header file here so you don't have to type that many lines of code.


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.


What is the use of header files as used in C programming?

Header files are used to have declarations. It is simple to include a single header file than writing all the needed functions prototypes.


What is the use of header file stdbool.h?

stdbool header file use for a new data type that is boolean value


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.