Structure Of C++ Program

Structure Of C++ Program

A C++ program consists of three main parts.
  • Preprocessor Directives
  • The main () Function
  • C++ Statements

Preprocessor Directives:

The instructions that are given to the compiler before the beginning of the actual program are called preprocessor directives.
These are also known as Compiler Directives. The preprocessor directives consists of instructions for the compiler. The compiler adds special instructions or code from these directives into the program at the time of compilation.
These preprocessor directives normally start with a number sign (#) and the keyword "include" or "define".
For example, preprocessor directives are used to include header files in the program.
A program example is given below. The first statement of the program is a preprocessor directive. This preprocessor directive has been written to include the iostream.h header file.

#include <iostream.h>
main()
{
cout <<"This is my first program";
}

Header File:

Header file is a C++ source file that contains definitions of library functions/objects.
The syntax to include header file is:
#include <name of the header file>

The main () Function:

The main() function indicates the beginning of the C++ program.
The syntax of the main function is:

main ()
{
program statement...
}
Creative Commons License
Pakistan How by Tahira Aijaz is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.