Introduction to C++

7 min 20 sec read Basic

At its core, the computer is just a processor which is capable of running the instructions like "Store 10 in memory location 2020". Why would we express a program as a text file in a programming language, instead of writing processor instructions?

Advantages of C++

  1. Portability
  2. Mid-level programming language
  3. Object-Oriented
  4. Multi-paradigm programming language
  5. Memory Management
  6. Fast and Powerful
  7. Similar to other languages
  8. Standard Library
  9. Community
  10. Scalability

1) Portability

In simple words, Portability in C++ allows the developers to write the code without caring much about the hardware. For example, you are working on Windows OS and for some reason, you have to switch to LINUX, the codes from Windows OS will also run in the LINUX OS without any error.

2) Mid-level programming language

As C++ supports the high-level programming features like developing the games and software applications along with the low-level programming features like developing the kernel and drivers to interact with the machine.

3) Object-Oriented

Object oriented programming as the name suggests, it is referring to an object.It aims to implement real-world entities like inheritance, hiding, polymorphism etc. The main aim of OOP is to bind the data and functions together so that no other part can access this data except that function. We will explore this topic in depth in coming tutorials.

4) Multi-paradigm programming language

You can think of Programming paradigms as the way to write the code. Generally, it is a best practice to plan the logic, the style, and how to implement the specific program and get it into action. C++ basically supports three paradigms,

  1. Generic – Using a single idea that serves multiple purposes.
  2. Imperative – Using steps that change the state of the program.
  3. Object-Oriented – Using methods and classes for reusability and modularity.

5) Memory Management

C++ supports the memory allocation in runtime. The runtime memory allocation is also called the Dynamic Memory allocation. Using calloc(), malloc(), free(), realloc() functions, c++ reserves the space in the memory.

6) Similar to other languages

C++ syntax is almost similar to most of the programming languages like C, C#, Java. C++ is a superset of C. That means, we can run all the C programs in C++ with .cpp extension

7) Standard Library

With better library support, C++ allows the programmer to develop the software applications much faster and cleaner. There are many built-in libraries available in C++.

8) Community

Communities that support C++ are very large in numbers. This makes C++ even more powerful because there are a lot of people who can provide help and support in case if you get stuck somewhere during development.

9) Scalability

Being in the IT industry, scalability is very important. As the number of users who use the application grows, it is important that applications should scale in that case. C++ provides scalability.

Hello World C++

Lets begin with the basic C++ program. Open codzify online C++ compiler and write this basic C++ program to see it in action.

using namespace std;

int main() {
 // your code goes here
  cout<< "Welcome to C++";
  return 0;


Welcome to c++

To run the C++ program, there are many editors like Notepad++, Visual Studio Code where you can write your C++ program without any internet connection. After code completion, you have to save it with some filename and .cpp extension. For example, we have saved our c++ code as filename.cpp Filename can be any name which signifies the purpose of that file. 

How to run a C++ program?

Open terminal in Mac, Linux or Command Prompt in Windows. Access the directory where your C++ file is stored. In our case, it is saved as "abc.cpp" file on desktop. Last step you have to perform is run the following commands one by one in the terminal or command prompt

cd Desktop
g++ abc.cpp

Welcome to C++

Line-By-Line Explanation

1) #include tells the preprocessor to dump in the contents of another file, here the iostream file, which defines the procedures for input/output.

2) When we want to access an identifier defined in a namespace, we tell the compiler to look for it in that namespace using the scope resolution operator (::). Here, we’re telling the compiler to look for cout in the std namespace, in which many standard C++ identifiers are defined.

4) int main() {...} defines the code that should execute when the program starts up

5) cout  is used to print the statements . It is like scanf() and printf() in C.language

6) return 0;  is used to return an int value because specified returntype before main() function is int .

Comments in C++

C++ Comment is written as follows:

1) /* This is a multi-line 
        comment syntax */

2) // This is single line comment syntax


An Identifiers in C++ are simply the names used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z, a to z, or an underscore '_' followed by zero or more letters, underscores, and digits (0 to 9). C++ does not allow punctuation characters such as @, $, and % within identifiers. C++ is a case-sensitive programming language. Thus, Programming and programming are two different identifiers in C++.

Tokens in C++

Every C++ program consists of various tokens. Tokens in C++ can either be a keyword, an identifier, a constant, a string literal, or a symbol. There are 4 tokens in the given example below,

cout                    --> 1st token
<<                      --> 2nd token
"Welcome to C++"        --> 3rd token                               
;                       --> 4th token

So this was the basic introduction to C++ programming. We will learn more about Datatypes, Access Modifiers, Pointers, Functions in C++, etc in the upcoming articles. 


1:1 & 1:Many Mentorship Program

Be job-ready. Learn how to crack the interviews with industry ready training program.

Learn More

Data Structures & Algorithms

What is Dynamic Programming and how to use it

This is a quick introduction to Dynamic Programming.

3 ways to check anagrams

Let's discuss the 3 ways to check anagrams and their time complexity.

Bubble Sort Algorithm

Topics covered: 1) Basics of Bubble Sort Algorithm 2) Worst Case, Best Case complexity

Introduction to Trees

What is a Tree and Terminologies like root, sibling, parent node, children, Leaf node, Ancestor & Descendant, Properties of Tree Data Structure, Depth of node, Height of node

Address Calculation in 2d array

Let's discuss about the Address Calculation using row-major order & column-major order.


Javascript - Postfix Vs Prefix

Let's discuss the difference between postfix and prefix with a practical example.

Javascript Identifiers, Variables

In this session, we will discuss the concept of identifiers, variables and operators in javascript with a practical example.


Bootstrap 4 Tutorial: Modal Popups Made Easy | Live Demo

Let's discuss the Modal Popups in Bootstrap.

How to create a dropdown list in navbar bootstrap

In this video, we will discuss How to create a dropdown list in navbar bootstrap with a practical example.

Navigation tabs in Bootstrap

Let's discuss about the navigation tabs in Bootstrap

Bootstrap Buttons

Let's discuss about the button classes in bootstrap.

Recommended tutorials