You are here: Home / Topics / Header file in C++

Header file in C++

Filed under: C++ Interview Questions on 2022-10-30 12:04:59

Actually the C++ commands are defined in different file which are called header files. When we use a command we must include the header file where it is defined. We include it as #include<iostream.h> where "iostream.h" is a header file. This way we can include as many header files as we need. The header files become part of our program so in order to keep the size of our pgrogram optimum we should not include header file which are not required. 
It is clear from the above two program structure that all the statements of C++ is terminated with semicolon. A block of statement is included within { } as done in main function. The main() function is a special function in C++, there may be number of functions in a progrm (to be discussed leter on). Every function must have a return type - it can be void, int, float etc. If return type is not mentioned in main then by default it takes int type. 
In Dev C++ an extra line using namespace std; must be added before main as shown above; and "main()" function to have int as return type.
In order to keep some comments in the program to describe the program like "what about the program is" or "to describe the use of a variable" etc., we can use "//" followed by the comment as shown above. This kind of comment is called single lined comment as it makes a line comment, the compiler simply skips these lines. Multi line comment also possible - start with /* the lines of comments */ as shown above 

About Author:
V
Vikram Tanwar     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.