Lesson2: C++ Program Basic Structure

.
.
.
.
.
.
// This is my first C++
Having the symbol // means it is a start of a comment line. Comments does not have any effect on the program behavior. This can be used by the programmer for short explanations within the source code itself. If the comment is more than one line, the symbol /**/ can be used instead.
#include <iostream>
Lines that start with pound sign # are directives for the preprocessor. These aren’t regular code lines and its main purpose is to include the iostream standard file. iostream includes the declaration of the basic standard input-output library in C++.
using namespace std;
namespace declares all the elements of the standard C++ library, along with the namespace is the name std. So for us to access its functionality, we always have to declare this expression.
int main()
Thin line defines the beginning of the main function. This is the point where all C++ programs start their execution. It doesn’t matter where in the program it is located because this is always executed fist.
cout<<”Welcome to your first C++ program. “;
This is an example of output statement. This statement performs the only action that generates a visible effect in our first program. This only means that the program will show the quoted words.
The semicolon at the end of the line states that it is the end of the statement. It must always be included at the end of all expressions.
return o;
This statement commands the program to terminate. A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ console program.
The output of the sample program:

.
.
.
.
.

C++ Tutorials « An Engineer's Literature said
[...] Lesson2: C++ Program Basic Structure [...]