At the code we find different type of statements that are written in different spaces of the script. The different locations and it’s syntax indicates it’s purpose and it’s functionality.
At first we find the include code. This lines links code that is written in other scripts and we can’t see explicitly on our code but can be used. In this code we link the iostream library that allow us to use different Input/Output methods. This include lines are called preprocessor directive because tells the linker functionality (a pre compiler functionality) which other scripts will be used at the code’s compilement.
main function, the starting function of any c++ application, starts with the next function syntax:
- int -> returning value
- main -> function’s name
- () -> no params needed
- { -> open bracket of the function’s code block
- […] -> code written here
And ends with the next statements:
- return 0 -> return statement that indicates a return value (value must be the same type of the returning value at the function’s signature. In this case 0.
- } -> close bracket of the function’s code block
We find two type of statements inside the main code. In one side we find expression statements that executes logic operations and allow the application to execute multiple functionality, and int other side the declaration statements that creates spaces where values product of the expressions can be stored. Store a value can be considered an expression statement by itself. So the code do the next:
cout functionality, at the first lines of main function, executes output functionality written at iostream script, declared at the preprocessor directive. In this output function we explain to the user what’s happening at the game and let him know the situation.
The next lines we declare a, b, c, sum and product constants. Constants are value containers like variables but can’t be changed once defined. Constants values must be defined at it’s declaration. A declaration statement must contain the type of the value that a constant/variable is going to contain and the name that we are going to reference in the code.
The assignement of values to a variable or constant can be considered expression statements. So at these lines we are declaring constant but we doing some maths in order to assign this values to them.
The last lines are the output statments to the user of the constants we declared at the previous lines.