From this site, " a C++ program is a collection of commands, which tell the computer to do "something". This collection of commands is usually called C++ source code, source code or just code. Commands are either "functions" or "keywords". Keywords are a basic building block of the language, while functions are, in fact, usually written in terms of simpler functions.
Think of it a bit like an outline for a book; the outline might show every chapter in the book; each chapter might have its own outline, composed of sections. Each section might have its own outline, or it might have all of the details written up.) Thankfully, C++ provides a great many common functions and keywords that you can use.
But how does a program actually start? Every program in C++ has one function, always named main, that is always called when your program first executes. From main, you can also call other functions whether they are written by us or, as mentioned earlier, provided by the compiler.
So how do you get access to those prewritten functions? To access those standard functions that comes with the compiler, you include a header with the #include directive. What this does is effectively take everything in the header and paste it into your program. "
Hahahahaha..sorry for just putting down some copied resources... By the way, just look at the example below. I have noted a simple explanation at the left side of the program.
Eg1. The Example Program of HelloWorld.cpp
The explanation. Please refer to the program code that is written in a yellow box. I love to refer this program source codes that's using Microsoft Visual C++ Compiler. In this compiler, we can see the differences by looking at difference colour of statement.
Comment. Usually we can recognize comment in green. Actually there are two types of comments in Microsoft Visual C++. Comment for a single line or comment for multilines.
If we want to write comment for a single line, we just start with // at the beginning of the comment line.For examples
//include this file for cout
//Filename: HelloWorld.cpp
Got it? ok now, let's look at a comment for multiple lines. If there is so, we use the /* symbol start the comment and we end the comment with */. Looks easy?. Look at the example
/*My first program in this
basic programming course is start with Hello World!*/
Have you seen the difference??
Ok next syntax is a preprocessor directive. We always used #include to write a command for preprocessor directive (in blue colour). This command allowed us to embed some library files or header files into our own program or else, we actually call for another program files that recognized as a header files into our own file. As an example
#include<iostream.h>
#include<math.h>
Next is a main function. For every C++ program there will be only one main function. main is a name for a function and from a main function, we can call another function that written by us.
Then, we look at the body of a function. We will start the block function with { symbol and at the end of the block we should end with } symbol. (I call these { and } symbol as a curly braces). So, our program coding will be written between these two braces.
So, this is what C++ all about... It just a beginning. There will be more syntax afterwards in next entries.