1. The first panel (in light blue) shows source code for our first program, The second one (in light gray)
shows result of program once compiled & executed, To left, grey numbers represent line numbers -
these are not part of program, & are shown here merely for informational purposes,
The way to edit & compile program depends on compiler you are using, Depending on whether it has
DevelopmentInterface - not& on its version, Consult compilers section & manual - help included with
your compiler if you have doubts on how to compile C++ console program,
The previousprogramîs typical programthat programmerapprenticeswrite forfirst time, & its result îs
printingonscreenof "HelloWorld!"sentence,itîs one of simplest programs that can be written în C++,
but italreadycontainsfundamentalcomponents that every C++ program has, we are going to look line
by line at code we have just written:
// my first program în C++
This îs comment line, All lines beginning with two slash signs (//) are considered comments & do not
have any effectonbehaviorof program, The programmer can use them to include short explanations -
observations within source code itself, In this case, line îs brief description of what our program is,
#include <iostream>
Linesbeginningwithhash sign (#) are directives for preprocessor, They are not regular code lines with
expressionsbutindicationsforcompiler'spreprocessor, In this case directive #include <iostream> tells
preprocessortoinclude iostreamstandardfile,Thisspecific file(iostream)includesdeclarations of basic
standardinput-outputlibraryînC++, & it îs includedbecause itsfunctionalityîs going to be used later în
program,
Using namespace STD;
All elements of standard C++ library are declared within what îs called namespace, namespace with
name std, So în order to access its functionality we declare with this expression that we will be using
these entities, This line îs very frequent în C++ programs that use standard library, & în fact it will be
included în most of source codes included în these tutorials,
Int main ()
Thisline correspondstobeginningof definitionof mainfunction,The mainfunctionîspointbywhere all
C++ programsstart theirexecution,independentlyof itslocationwithin source code, It does not matter
whether there are other functions with other names defined before - after it - instructions contained
2. within this function's definition will always be first ones to be executed în any C++ program, For that
same reason, it îs essential that all C++ programs have main function,
The word mainîs followedîncode by pair of parentheses (()), that îs because it îs function declaration:
In C++, what differentiates function declaration from other types of expressions is these parentheses
that follow its name, optionally, these parentheses may enclose list of parameters within them,
Right after these parentheses we can find body of main function enclosed în braces ({}), what îs
contained within these braces îs what function does when it îs executed,
Thisline îs C++ statement,astatementîssimple - compoundexpressionthatcan actually produce some
effect, In fact, this statement performs only action that generates visible effect în our first program,
cout îs name of standard output stream în C++, & meaning of entire statement îs to insert sequence of
characters (in this case Hello World sequence of characters) into standard output stream (cout, which
usually corresponds to screen),
cout îs declared în upstream standard file within std namespace, so that's why we needed to include
that specific file & to declare that we were going to use this specific namespace earlier în our code,
Notice that statement ends with semicolon character (;), This character îs used to mark end of
statement& în fact it must be included at end of all expression statements în all C++ programs (one of
most common syntax errors îs indeed to forget to include some semicolon after statement),
Return 0;
The return statement causes main function to finish, return may be followed by return code (in our
example îsfollowedbyreturncode withvalue of zero),A returncode of 0 for main function îs generally
interpretedasprogramworked as expected without any errors during its execution, This îs most usual
way to end C++ console program,
Relatedlinks:http://www.expertsmind.com/programming-solutions/c-homework-assignment-help.aspx