Basic structure of C++ Program

  • Home
  • Basic structure of C++ Program
Shape Image One

BASIC STRUCTURE OF C++ PROGRAM

advanced divider

C++ program is mainly divided in three parts:

  1. Pre-processor Directives
  2. Main Function Header
  3. Body of program / Function

BASIC STRUCTURE OF C++ PROGRAM IS GIVEN BELOW:

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. statements;
  6. return 0;
  7. }

EXPLANATION OF BASIC STRUCTURE

  • #include<iostream>

The statement starts with # symbol is called pre-processor directives. This statement tells the pre-processor to include the contents of iostream header file in the program before compilation. This file is required for input-output statements.

  • using namespace std;

This statement is used to instruct the compiler to use standard namespace. A namespace is a declarative location that provides a scope to the identifiers. Namespace std contains all the classes, objects and functions of the standard C++ library.

  • int main()

This statement is a function and used for the execution of C++ program. int means it returns integer type value.

  • {

This symbol represents the start of main function.

  • statements;

Statements are instructions that performs particular task. Statement terminator (;) is used to end every statement in C++ program.

  • return 0;

This statement is used to return the value to the operating system. By default, main function returns integer value 0.

  • }

This symbol represents the end of main function.

Quiz

advanced divider