C++ Program structure

Before we study the basic building blocks of the C++ programming language, let us look at the C++ program structure. For Example Hello World.

  • Preprocessor Commands.
  • Functions.
  • Variables.
  • Statement & Expressions.
  • Comments.

OUTPUT

Let’s understand this Program:

1) // my first program in C++
This is a comment line. All lines beginning with two slash signs (//) are considered comments. This Comments are ignored by the compiler and are used to provide useful information about the program to humans who use it.
2) #include<iostream>
Lines beginning with a hash sign (#) are directives for the preprocessor which tells the compiler to include iostream.h file.
3) using namespace std;
All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. So in order to access its functionality, we declare with this expression that we will be using these entities. This line is very frequent in C++ programs that use the standard library.
4) int main ()
C++ programs consist of one or more functions. There must be one and only one function called main. The brackets following the word main indicate that it is a function and not a variable.
5) cout << “Hello World!” ;
It is predefined in C++ to correspond to the standard output stream and the meaning of the entire statement is to insert a sequence of characters (in this case the Hello World sequence of characters) into the standard output stream (which usually is the screen).
6) return 0;
The return statement causes the main function to finish.return 0 means statement returns value 0 from the main() function.