Day: September 20, 2015

‘Hello World’ in C++

In lesson on Tuesday we were using Adobe Flash to create the ‘Hello World’ program using code. We were given the task to create the Hello World program at home using a different language. I decided to use C++. As i have never used C++ before i had a tutorial to help me. Here is the code:

// my first program in C++
#include <iostream>

int main()
{
  std::cout << "Hello World!";
}


The // on the first line allows you to type any text you wish, without altering the code. This is so you can easily seperate lines of code without making a mistake.

Lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor. They are special lines interpreted before the compilation of the program itself begins. In this case, the directive #include <iostream>, instructs the preprocessor to include a section of standard C++ code, known as header iostream,

Int main(). This line initiates the declaration of a function. Essentially, a function is a group of code statements which are given a name: in this case, this gives the name "main" to the group of code statements that follow.

The open brace ({) at line 5 indicates the beginning of main's function definition, and the closing brace (}) at line 7, indicates its end.

st::cout << "Hello World!"; .This line is a C++ statement. A statement is an expression that can actually produce some effect.