| Introduction to C++

Important Dos & Don'ts in C++

Basic C++ Syntax

First of all, notice there is #include <iostream> in the first line. iostream is the header library in C++, which would allow us to use cout“.

cout : is used to output. (we will discuss it later).

cin : is used to take the input (we will discuss it later).

In the second line, we have using namespace std, it is an abbreviation for standards, we are going to use it. Otherwise, we will have to declare it every time we use the names and variables from standard library. We will understand this in detail later.

Finally, we have int main() { }, this syntax must be included in every c++ program. You are going to code inside the curly brackets where it says “You will code inside here”.

1) Writing your first "Hello World!" program

In order to write your first program, follow the instructions: 

1) Write down all the code shown above.

2) Secondly, Write this line of code inside the curly brackets.

Hello World Program

Let’s scrutinise this to comprehend the logic behind this code. 

Firstly, we have “cout“. It is used to output the content in the C++. It is always used first, meaning that any line of code that outputs something has cout as a start word like the code shown above.

Secondly, we have “<<” after cout. << is also known as insertion operator. It must be used after the cout like in the code above. Otherwise, the error will be shown.

Thirdly, we have our text “Hello World”. Whenever we have write any kind of text in the C++, we must have quotation marks “your_text” around the word.

Then, we have endl. It is used to move onto other line. For instance, if we were to have to outputs for the “Hello World!”, they both will be displayed on two different lines instead of one line.

Eventually, we have “;”.  It must be used after every line of code in the C++.

2) Output your name and age with space in between.

Name & Age

This is quite simple as we are going to simple write two lines outputting our name and age like show above.

3) Output your name and age with only one line of code.

C++

\n is the newline character, which is also called escape sequence as well. If you place it in the line, it will perform exact same task as the endl, which means that the output will be displayed on two lines.