Skip to content
Home » Blog » Introduction to C++ now in a Beginner Friendly Version

Introduction to C++ now in a Beginner Friendly Version

C++ is often considered one of the most complicated programming languages to learn. It is considered to be bloated by many as it has a lot of features. But it is not necessary to know everything to create outstanding software with the language. C++ is used to develop operating systems, games, desktop apps, etc. We will learn about various C++ concepts in this series of blogs that I will be writing.

What is C++?

C++ is one of the most popular programming languages out there. It is a compiled programming language. A compiled language is where a software called the compiler translates the source code we write to an executable file(object file). Think of the compiler as a foreign language translator who writes whatever you say into a piece of paper and hands it back to you can then show that piece of paper to whoever you want to convey your message to. Similarly, C++ translates our code to an executable file(assuming there are no syntax or runtime errors) which we can execute whenever we want. An interpreted language on the other hand translates our code line by line. Think of it as a translator that repeats whatever we say in a foreign language in real-time.

Setting up our compiler

We know that C++ is a compiled language and we would need a compiler to create executables of our C++ code so the first step will be to install a compiler. We will be using the MinGW compiler if you are on a Linux-based OS then MinGW must be installed by default.

For Windows users:

For windows used they can download the compiler by clicking on this link:

After downloading the executable go through the installation process. After we are done with the installation we need to add the compiler to our PATH variables. The steps for doing that are given below:

  • Navigate to the folder where you have installed the compiler and then go to the “bin” directory inside it. Then copy the path to the location by clicking on the bar at the top of the file explorer.
Selecting folder from file explorer
  • Right-click on this PC and select properties. A new settings window will appear and scroll down till you find advanced system settings.
  • Select environment variables in the system properties window.
System Properties window
  • In the “environment variables” list click on PATH and then click Edit
The PATH variables
  •  In the new window click on new, enter the path then click OK to apply.
PATH Editor
  •  To verify if we have done it right open up cmd and type “g++ –version” if we see a   version number as the output then congrats you have done it all right if not then I recommend revisiting step 1 to 5.

A Quick Note on the Text Editor

You can use any text editor of your liking. I would recommend VS Code if you are a complete beginner. I won’t go through the steps for installing VS Code as it’s a fairly simple process. 

P.S.: If you are using I would recommend installing the C/C++ extension in VS Code via the Extensions tab.

Hello World in C++

Create a new .cpp file and type the given code. Then I will explain the code line by line.

#include <iostream>

int main()
	// Hello World in C++

		A multi line comment in C++


	std::cout << "Hello World!" << std::endl;
	return 0;

After you type this code let’s compile it and run it.

Navigate to the directory where you have saved the .cpp file and then run:

g++ <filename> -o <name-of-executable>

The -o flag signifies what the name of the executable should be; remember C++ is a compiled language that produces .exe or .o files depending on OS, you can use any name of your liking. Now when you list the files in the directory you will see a new .exe file execute the .exe file by running:


P.S.: Anything within the <> brackets in the above paragraph isn’t constant, it will depend upon you. For example the file name and what you want the name of the executable to be.

Once you are done with this let’s go through the code line by line.

Demo of compilation process

Including Header files

The line “#include <iostream>” includes the “iostream” header file. The “iostream” header files include the definition of classes and functions defined in the “iostream” library. When we make a cake we don’t need to grow crops from scratch we get it pre-built from the store similarly while programming we don’t need to reinvent the wheel a lot of things is pre-made for us. “iostream” is such a file that stores all these predefined functions and objects. We will study what objects and functions in later blogs for now just think that they help us accomplish stuff.

So now we can use the functions and objects defined in the “iostream” library.

Main function and its significance

Every C++ program includes the “main” function. It is the starting point of our C++ program. The computer will execute every instruction written within the “main” function. The compiler will look for the “main” function as the compilation process begins.  A function is a block of code that performs a certain task. A function in C++ may or may not return something to us. We prefix the function name with a data type. A function having a datatype void will return nothing while a function with data type int returns an integer.

The syntax for the function is: 

datatype name(arguments)
   return value;

The main function by convention has a data type int i.e. it will return an integer upon exit. “return 0” specifies that the program exits without any error. In C programming can also have a main function having void data type but it’s a convention to use int in most cases. C++ though throws a compiler error if we break this convention.

We will later learn more about functions in detail.

Comments in C++

Let’s cover the comments very quickly. They are the simplest thing to understand. Comments are not executed by our computer, they are meant for fellow programmers to understand our code better. There are two types of comments in C++ single-line comments and multi-line comments. The difference between them is quite obvious: a single-line comment spans across a single line while a multi-line comment spreads across multiple lines. The syntax for comments is given below:

// single line comment

 multi line 

Outputting with “cout” in C++

The line “std::cout << “Hello World” << std::endl;” is responsible for printing “Hello World” to the screen. “cout” is an object which is part of the “ostream” class; the right shift(<<) operator is modified i.e. overloaded to insert what should be displayed on the console. The shift operators(<< and >>) have very different significance but in this case, their use case is modified. For example, in our day-to-day life, we can use a water bottle to store water as well as to act as a paper load. Here the use case of the water bottle was modified by us to do something that it wasn’t meant to do, similarly, we can change the use cases of C++ operators with the concept of operator overloading. We will learn more about operator overloading later. 

Finally, let’s discuss the “std::” part “std” is the namespace of which the “cout” class is part. Let’s understand namespaces with another nifty example. Let us consider you have two friends, both of them have a common name, Aman. One of them is from Delhi and the other is from Mumbai to address a particular Aman we can mention his city for example “Aman from Delhi” or “Aman from Mumbai” here the city is what allows us to know which Aman is being addressed. Similarly, we may include libraries in our C++ program, they may have functions and classes with identical names, so a namespace allows us to identify the compiler in which library the function or class is defined.

Note: Here we are specifying namespace by adding “std::” in front of every instance of the cout class. Alternatively, we can add “using namespace std” just after the “#include<iostream>” line but it is a very good practice to declare namespaces inline using the scope resolution operator(::) rather than declaring it globally to avoid namespace collision errors.


So that’s it for this blog. I hoped it helped you to understand the basics of C++. I will love to have reviews in the comments below.

2 thoughts on “Introduction to C++ now in a Beginner Friendly Version”

Leave a Reply

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