How to write first code in C++? – Hello Procademy!

C++

Before writing a code you need to understand the definition of the program.

The program is just a collection of different commands. The machine performs these commands or statements step by step. Now see the simple structure of the program written in C++.

#include <iostream>
using namespace std;

int main()
{
  cout << "Hello Procademy!";
  return 0;
}

When you write this code in your code editor and run it, the “Hello Procademy” message will be indicated.

Let’s explain each part of this code.

#include <iostream>

Almost all programming languages have various libraries or header files that provide special functionality for your program. This program calls the <iostream> header file.

# – the number sign at the beginning of a line targets the compiler’s pre-processor. Here, #include tells the pre-processor to include the <iostream> header. This header file is needed for input and output data.

In order to improve the visual attractiveness and readability we can use the blank lines. C++ compilers ignores them.

The line using namespace std includes the features of the C++ Standard Library.

C++ always executes the main() function first irrespective of what the program does. int is the type of this function. it belongs to integer values.

Curly brackets { } shows the beginning and end of the function and it can be called function’s body.

cout is the keyword, stream object of C++ which displays the data on the screen.

<< is the insertion operator that inserts the data after the stream.

As many programming languages, the semicolon is used to terminate a statement.

return is a last instruction of the program that terminates the function with somehow value according to the type of this function.

Because of main function’s type is int, this function must return integer value. It does not matter what value it is from integer set. However, main function usually returns 0 (zero). Other values are considered just abnormal way.

Leave a Reply

Your email address will not be published. Required fields are marked *