Learn programming

First c++ Program-Hello World!

As we have already discussed enough about basic c++  introduction, and also about the Syntax of a c++ program so now we are ready to start our first programming example. The very first program which is very easy and also used widely in learning a programming language; writing a single phrase on the screen. First i present you the code , and then i will discuss what it actually means.


  1. #include<iostream.h>
  2. void main ()
  3. {
  4. cout <<" Hello World! ";
  5. }
The first line tells the compiler that we want to link the iostream.h library to our program. A Library is a kind of repository that stores codes, called functions, which we can use. They also store variables and operators. The “iostream.h “Library contains code that allows us to use output and input statements.

The second line “Void main () “indicates the beginning of a C++ program. The function “main ()” must be included in every C++ program. When a C++ program is executed, the control goes directly to the “main ()” function. The statements within this function are the main body of the C++ program. If main () function is not included, the program is not compiled and an error message will be generated.
The third line of the code is the starting of actual programming cod, which is also called code block. Everything inside those braces ({}) are read and translated by the compiler, we always need this starting “{“ in our codes, if not nothing will happen, and it would be useless.
The Fourth line of the code is the actual statement that we want to output or show on the screen, For that we need to use some codes which is already stored inside iostream.h that we have already discussed. The cout sends output to the computer screen that we have discussed it in earlier post.
At the end of the following topic you may find more about" Cout".
Check it here ---- > The "cout"object-output stream
This ( << ) is called an operator which means output and together with cout , it means send output the following to the screen. The “Hello World! “Is called a string. A String is a sequence of characters which are shown and enclosed inside double quotation marks.
Note: This line ends with semicolon (;) which represents the ending of this statement, and if not used the program won’t be compiled.
In the last you have to use that closing braces (}) which shows the ending of the code blocks ,if not used the program won’t be compiled.
Now you may compile your source program.
Important: If your program closes straight away, you may use” getch(); “ function before the closing of the programming block to stop the output on the screen.

If you’re having any difficulty you may ask It in the comment section.

Written by : Maisam Afshar

Previous
Next Post »