answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can Header file be called in main function or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between program and programing?

the program contains the which are coding like as our header file ,void main,library function etc.


Difference between library file and header file?

EX: pgm #include<stdio.h> main() { printf("haiii"); } Header file: (1) contains the function(printf) declaration (2) during preprocessing, the printf function is replaced by the function declaration Library file : (1) contains the function(printf) definition (2) during linking, the function declaration is replaced with the function definition.obviously, everything will be in object while linking


What is the following warning in a function where msg is a function name without prototype?

In C, each function needs a prototype declaration in the header file so that it can be called from outside of its immediate domain. To speed up compiling, the compiler only looks in the header files for function declarations. This greatly speeds up compiling when the function being called is located in another file. This way, it doesn't have to scan the whole file to make sure you didn't make a mistake. All you need to do to clear this error is to include a function prototype in the header. I'm not sure about C, but you *might* be able to get away with declaring the function at the beginning of the .c file. Example: --(file helloworld.h)-- long msg(int, int, char *); //this is the prototype --(file helloworld.c)-- #include "helloworld.h" void main() { msg(1,5,"Hello World"); } long msg(int x, int y, char *message) { //code to display message here } Notice that the prototype only needs the data types, and not the variable names. If you don't want to bother with a header file, you can try putting your declarations at the beginning of your .c file (after the preprocessor directives), I know I've done it that way before but I'm not sure in which cases it will work.


What you meant by function call function definition and the function declaration in c and c plus plus?

A function call is a function that is called from within another function. Functions must be declared before they can be called, in order to establish the function's prototype (signature) so the compiler knows which function to call. The function definition contains the implementation of the function and may be specified in the declaration itself (inline), or it can be defined in another file altogether. Declarations are typically placed in a header file so that they may be included (#include) in any files that require them, including the file containing the definition of the function declared in the header file. Including a file is the same as typing the file contents in full at the point of inclusion, thus ensure the declarations are available to the compiler before they are used. The following example shows a forward declaration of a function that is defined later. // forward declaration. int square(int); // the main function (the entry point of application). int main() { // a function call. int s = square( 5 ); // returns the value 25 to the calling process (e.g., the operating system). return( s ); } // definition of the function declared earlier. int square(int data) { // returns the square of the data to the calling function, e.g., main(). return( data * data ); } Function is a self contained block or a sub program of one or more statements that performs a special task when called.


In a header file whether functions are declared or defined?

Ideally, functions should only be declared in a header and defined in a translation unit (source file) that includes the header. However, trivial functions are often defined in a header as they are usually good candidates for inline expansion, but you must remember to declare the function inline. Often it is better to forward declare inline functions so that maintainers are not distracted by the implementation details which can be placed towards the end of the header, out of the way. However, a definition is also a declaration, so forward declaring an inline function is not a requirement unless there is a cyclic dependency issue where a forward declaration is necessary to break the cycle.

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"


What is the difference between program and programing?

the program contains the which are coding like as our header file ,void main,library function etc.


Difference between library file and header file?

EX: pgm #include<stdio.h> main() { printf("haiii"); } Header file: (1) contains the function(printf) declaration (2) during preprocessing, the printf function is replaced by the function declaration Library file : (1) contains the function(printf) definition (2) during linking, the function declaration is replaced with the function definition.obviously, everything will be in object while linking


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.


What are the main type of header file?

stdio.h strlen.h conio.h math.h


What is the structure of c prgramming?

A header file , a main part and a body


What is the following warning in a function where msg is a function name without prototype?

In C, each function needs a prototype declaration in the header file so that it can be called from outside of its immediate domain. To speed up compiling, the compiler only looks in the header files for function declarations. This greatly speeds up compiling when the function being called is located in another file. This way, it doesn't have to scan the whole file to make sure you didn't make a mistake. All you need to do to clear this error is to include a function prototype in the header. I'm not sure about C, but you *might* be able to get away with declaring the function at the beginning of the .c file. Example: --(file helloworld.h)-- long msg(int, int, char *); //this is the prototype --(file helloworld.c)-- #include "helloworld.h" void main() { msg(1,5,"Hello World"); } long msg(int x, int y, char *message) { //code to display message here } Notice that the prototype only needs the data types, and not the variable names. If you don't want to bother with a header file, you can try putting your declarations at the beginning of your .c file (after the preprocessor directives), I know I've done it that way before but I'm not sure in which cases it will work.


Which header file is used for main function in cand c plus plus languages?

None. PS: The most common headers files are probably: stdio.h stdlib.h string.h


What you meant by function call function definition and the function declaration in c and c plus plus?

A function call is a function that is called from within another function. Functions must be declared before they can be called, in order to establish the function's prototype (signature) so the compiler knows which function to call. The function definition contains the implementation of the function and may be specified in the declaration itself (inline), or it can be defined in another file altogether. Declarations are typically placed in a header file so that they may be included (#include) in any files that require them, including the file containing the definition of the function declared in the header file. Including a file is the same as typing the file contents in full at the point of inclusion, thus ensure the declarations are available to the compiler before they are used. The following example shows a forward declaration of a function that is defined later. // forward declaration. int square(int); // the main function (the entry point of application). int main() { // a function call. int s = square( 5 ); // returns the value 25 to the calling process (e.g., the operating system). return( s ); } // definition of the function declared earlier. int square(int data) { // returns the square of the data to the calling function, e.g., main(). return( data * data ); } Function is a self contained block or a sub program of one or more statements that performs a special task when called.


In a header file whether functions are declared or defined?

Ideally, functions should only be declared in a header and defined in a translation unit (source file) that includes the header. However, trivial functions are often defined in a header as they are usually good candidates for inline expansion, but you must remember to declare the function inline. Often it is better to forward declare inline functions so that maintainers are not distracted by the implementation details which can be placed towards the end of the header, out of the way. However, a definition is also a declaration, so forward declaring an inline function is not a requirement unless there is a cyclic dependency issue where a forward declaration is necessary to break the cycle.


Why you have begin with main function?

You don't have, it's only the program-execution which begins with the main function, but it doesn't have to be the first function in the source-file.


What is header file in computer programming?

A header file is used in some languages to declare functions that will be used but are not yet defined in the current source code. This is primarily used by C and C++, and usually for library functions and user-defined functions that are stored in separate files and folders than the main source code file.