position: fixed; top: auto !important; margin-left: 112px;

Introduction to C++

C++ is middle-level programming language which means it supports both high level and low-level programming features. It is not purely an object-oriented programming language as some of the features in C++ like friend functions violates the philosophy behind the object-oriented feature.

C++ is used in various system drivers, most antivirus software is written in C++. It was developed by Bjarne Stroustrup in 1979. C++ is considered as static type programming language. A programming language is said to use statically typed when type checking is performed during compile-time as opposed to run-time.

Features of Object Oriented Programming

  1. Encapsulation
  2. Polymorphism
  3. Inheritance
  4. Data Hiding

We will explore each of these topics in upcoming articles in detail. First we cover the basics of simple C++ program.

Basic Syntax

Open any text editor like notepad,notepad++ or sublime or any other editor you are comfortable with, write this program and save it as abc.cpp at your destination like on Desktop.

#include <iostream>
using namespace std;

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

How to run a program in C++?

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. Type the commands one by one and hit Enter.

cd Desktop
g++ abc.cpp

Welcome to C++

Various parts of program in c++ are explained below :-

1) #include :- is used to include something in a program.

2) <iostream> :- is used to include all the functions and libraries written in this file for the use of programmers like cout,cin etc.

3) using namespace std :- says use a namespace named std.

4) int main :- is starting point of eecution . That means Function is called first whenever you executes a program.

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

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++.

abc , _abc , abc_123 are valid tokens
$abc,#abc,abc$ are not valid tokens . 

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 if you noticed,7

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

Baisc Introduction of Classes & Objects

Consider the class as a Home. Home can be of various types like Bunglow, Palace, Flats. So consider class as a blueprint at high level which consists of various properties & methods.

Open text editor notepad,notepad++ or sublime or any other editor , write this program and save it as PQR.cpp

#include <iostream>
using namespace std;
 class PQR
 int i;                   //data variable
  void  display()         //Member Function
   cout<<"Always remember by default methods are private in C++ :)";
}; // Class ends here

int main()
 PQR pqrObject;         // Creatig PQR class's object
 pqrObject.display();   //Calling member function using class object


Open terminal ,

g++ PQR.cpp

Always remember by default methods are private in C++ :)

This was just the basic introduction to C++. We will explore each and every topic in detail we discussed here. Just go with the flow. Have a look on next article of Datatypes in C++ you should know.

Solve the Quiz of Article

1) Is C++ is a "multi-paradigm" programming language?

2) Can C++ Identifiers be used as a keyword?

Previous Next Article


Largest collection of up-to-date tutorials to learn programming languages. We are focused on easy learning. Massive collection of interview questions one may need for preparation.

Social Profile


Copyright 2018. All rights reserved.