Home / Computer Courses / Basic Structure Of C++ Program

Basic Structure Of C++ Program

Basic Structure Of C++ Program

The format of writing C++ program called its structure. The basic structure of C++ program is easily adoptable. The basic structure of C++ program enhance the power of language. It consists of the followings parts :

  • Preprocessor directive
  • Main function
  • Program body

structure of c++ program

   1)   Preprocessor directive:

Preprocessor directive is an instruction gives to compiler before the execution. It is also know as compiler directive. The preprocessor directives start with the Hash symbol ‘#’. These directives write at the start of the program. The include preprocessor directive uses to add header files in the program. For example:

#include<iostream.h>

This statement is showing that compiler include the header file iostream.h in the program. Other some examples are:

#include<stdio.h> and #include<dos.h> etc

Header files:

Header files are the collection of library functions to perform specific tasks. Different header files use for different purpose. Each header file contains the predefined functions. We can add more than one header files in the program. The extension of a header file is ‘.h‘. The header files normally store in ‘include’. The name of the header files write in angle brackets.

Syntax:

#include<header_file_name>

Example:

#include<iostream.h>

Here, ‘iostream’ stands for input/output stream. It is used to add predefined input/output functions and objects.

   2)   main() function:

The main() function is the staring point of a C++ program. When the program run, the compiler execute the code from the main() function. Each program must contain the main() function. If a program does not contain the main() function, it cannot be execute. Any number of statements write in the main() function.

Syntax:

void main()

{

body of the function

}

 

Before Going Next, We Have Some Recommended for you!!!

 

   3)   C++ statements:

The statements of the program write in the curly braces. These braces are also called the delimiters. ‘{‘ brace is called opening brace and ‘}’ brace is called closing brace. Collectively, these statements actually called the body of the program and we know that body of the program write after the main() function. Each statement is terminated by semicolon ‘:’. These statements are the instructions for the computer to perform the tasks. Computer perform these instructions in a sequence.

Example:

cout<<“Hello FS tech”;

Conclusion:

The summary of the above statements for the basic structure of C++ program is:

#include<iostream.h>

void main()

{

cout<<“hello FS tech”;

}

In this program:

  • ‘#’ hash is a symbol that is used before the directive.
  • ‘include’ is preprocessor directive.
  • ‘iostream.h’ is header file.
  • ‘main()’ is a function.
  • And all statements in the delimiter is the body of the program.

About Shumaiza Asghar

Shumaiza Asghar

Check Also

Types of Identifiers with Examples in C/C++ Language

Types of Identifiers with Examples in C/C++ Language

What is Identifier, Types of Identifiers in C/C++ Language | MyFSTech.com The identifiers are the …

Leave a Reply

Your email address will not be published. Required fields are marked *