answersLogoWhite

0


Best Answer

Hi...

It's pretty simple. The .h stands for the word "header." It's merely a C convention that has been used throughout the years.

Conceivably, you could have "header" or "include" files with different extensions - the .h is the convention.

John

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why the header files have .h extension only?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you create a user defined header file?

Header files are not much different from usual cpp files. There are basically two different things. It's file extension: you need to choose "header file" when you create it or save as .h file. Second is header files do not have main() function. When you are done with you header file do not forger to include it in your project by writing preprocessor directive:#include "your_header_file.h"


A program in c plus plus will run without an extension name CPP?

Yes. cpp is merely a convention to differentiate C++ source code from C source code, just as hpp is used to differentiate C++ header files from C header files (*.h). But they are just conventions, not rules: you can use any extension you like for both header and source files. For example, there's nothing to prevent you using the cpp extension for a header file. However, using the conventions makes it much easier to organise and recognise your files.


Why .h extension is used with headerfiles?

Its simply a convention. You can use whatever extension you want.For me, h is quite plausible for header.


Why to use header file to easy know?

in the java as we use the inheritance property in the same way we can get the the inheritance property in c by using the prepared header files( .h files). there a single program in c use the many methods of many header files like math.h give us to use the use of floor(), sqrt() e.t.c. functions..


Why there is no need to include header files in c but it requires header files if saved with the extension of .cpp?

Not sure what you mean by not including header files in C. If header files contain declarations that are vital to your code, then you must include them. The same is true in C and C++, regardless of the file extension. Generally speaking, source files (.c and .cpp files) need to include all required headers (.h or .hpp files) while the headers themselves need only make forward declarations (known as incomplete types). There are exceptions, however. You cannot declare values of an incomplete type (only pointers and references can be incomplete), nor can you dereference an incomplete type. You also cannot derive a new class from an incomplete base class. Thus if any header falls into any of these categories then they must include the required headers rather than simply forward declare the incomplete types. Template classes are also regarded as incomplete if the entire definition is not available at the point of instantiation. For this reason, class templates cannot be split between header and source files like normal classes (the entire definition must be placed in the header) and the header must be included prior to each instantiation. Similarly with template functions.


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 are the uses of macros?

With macros, you can perform long or boring tasks just by a single click or keystroke combination. Also, you would not need to repeat the same action over and over again.


Why we use extension as cpp in c plus plus programs?

Source files use a .cpp file extension, while headers use .hpp. However, this is merely a convention. Most C++ programmers use .h for all headers, even though this convention implies a C-style header rather than a C++ header. Ultimately, the extension is immaterial. If the file can be included in other files, then it is a header, otherwise it is a source file.


Can Header file be called in main function or not?

No, main.c does not require a header file. When you have a ".c" and ".h" pair, the ".h" file is to declare the existence of functions that are defined in the ".c" files so that these functions can be called in other files. since "main.c" needs the headers of the other modules (to access their data types and functions) but usually doesn't have a header file itself.Header files aren't "called", they are "included",but usually not inside any function.


How do you add a new library for Dev C plus plus?

If you want to know about adding new header files, then it is simple. Write your functions in a file. Save that file with extension .h in the include directry. Now, you can include this file using the #include directive


What does the header file in c consists of?

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.


What are the header file used in c plus plus?

Header files are many and varied. The standard library headers have no extension while C-style headers have a .h extension. User-defined C++ headers typically have a .hpp header (corresponding to the .cpp source file that implements the header). Header files exist to allow multiple source files as well as other headers to make use of the same declarations without having to type them out in full. By using the #include directive you are effectively copy/pasting the contents of the header into your source file. However, during compilation, headers can only be included once per translation unit. To facilitate this, headers employ compiler-directive header guards (macros) that ensure the header file's content cannot be included more than once. For instance, a header file named MyHeader.h would use the following header guard: #ifndef _MYHEADER_H_ #define _MYHEADER_H_ // content of header goes here #endif _MYHEADER_H_ When the compiler encounters this file for the first time, _MYHEADER_H_ will not be defined, thus _MYHEADER_H_ becomes defined and the content will be included. On all subsequent occasions where this file is included, _MYHEADER_H_ will already be defined thus the content will be ignored. This mechanism places the onus entirely upon the compiler to ensure the file is only included once regardless of how many files need to include this file. Once included, those other files will "see" the declarations. There's no point trying to be clever and doing it yourself because with modular programming there's no guarantee that the file that includes your header will be visible to other programs. As with most things in compiled languages, it's always best to let the compiler do as much donkey work as possible. It's there to help you so it pays to enlist its help at all times.