×

C++ Features

C++ is a general-purpose programming language that evolved from the C language to include an object-oriented paradigm. It is a compiled and imperative language.

Features of C++

Object-Oriented Programming

Object-oriented programming language concepts:

  • Class
  • Objects
  • Encapsulation
  • Polymorphism
  • Inheritance
  • Abstraction

Class: A Class is a C++ building piece that leads to Object-Oriented programming. It is a user-defined data type with its own set of data members and member methods that can be accessed and used by setting up a class instance.

Objects: An Object is a recognizable thing that has certain qualities and behaviours. A Class's instance is an Object.

Example:

class Man
{
char name[20];	
int id;
public:
void getdetails(){}
};
int main()
{
Man M1; // M1 is a object
}

Encapsulation: Encapsulation is the process of encapsulating data and information in a single entity. Encapsulation is described as the coupling of data and the functions that replace it in object-oriented programming.

Abstraction: One of the most fundamental features of object-oriented programming in C++ is data abstraction. Abstraction refers to revealing only the most important information while hiding the intricacies.

Polymorphism: Polymorphism refers to the fact that something exists in multiple forms. Polymorphism, in simple words, is the ability to present a message in multiple formats.

Inheritance: Inheritance refers to the ability of one class to inherit features and traits from another class. One of the most important features of object-oriented programming is inheritance.

Machine Independent

A C++ executable is not platform agnostic (compiled Linux applications will not run on Windows), but it is machine agnostic. Let us look at an example to understand this C++ feature better. Assume you've built a piece of code that runs on Linux, Windows, and Mac OS X, making C++ Machine Independent.

Simple

It is a simple language in the sense that programs can be broken down into logical units and fragments, and it supports a large number of library functions and data types. In addition, the C++ Auto Keyword makes things easier.

Example:

#inlcude<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
auto a_int = 10;
auto a_bool = false;
auto a_float = 30.43;
auto ptr = &a_float; 
cout << typeid(a_bool).name() << "\n";
cout << typeid(an_int).name() << "\n";
return 0;
}

OUTPUT

b
i

High-Level Language

Unlike C, which is a mid-level programming language, C++ is a high-level language. Working with C++ is easy since it is a high-level language that is closely related to the human-comprehensible English language.

Popular

C++ may serve as a foundation for a variety of other programming languages that enable object-oriented programming. Simula 67, the first object-oriented language, lacked simulations, thus Bjarne Stroustrup chose to create C++.

Case-Sensitive

C++ is unmistakably a case-sensitive programming language. To take input from the input stream, for example, cin is utilized. But what if "Cin" doesn't work? Other languages, such as HTML and MySQL, are case-insensitive.

Compiler Based

Unlike Python, C++ is a compiler-based language. C++ applications are compiled, and their executable files are utilised to run them. As a result, C++ is a speedier programming language than Java and Python.

Dynamic Memory Allocation

The variables are assigned dynamical memory space when the programme executes in C++. Variables are allocated in the stack area within the functions. We often don't realise how much memory is necessary to store certain information in a defined variable until it's too late, and the quantity of required memory may be established at run time.

Memory Management

  • In C++, we can allocate memory for a variable or array during runtime. There is a term dynamic memory allocation for this.
  • The compiler handles the memory assigned to variables in other programming languages, such as Java and Python. In C++, however, this is not the case.
  • In C++, dynamically allocated memory must be manually allocated when it is no longer needed.

Example:

#include <cstring>
#include <iostream>
using namespace std;
// Driver Code
int main()
{
int num = 5;
float* pt;
// Memory allocation of
// num number of floats
pt = new float[num];
for (int x = 0; x < num; ++x) {
*(pt + x) = x;
}
cout << "Display the GPA of students:"<< endl;
for (int x = 0; x < num; ++x) {
cout << "Student" << x + 1<< ": " << *(pt + x)<< endl;
}
// Pt memory is released
delete[] pt;
return 0;
}

OUTPUT:

Display the GPA of students:
Student1: 0
Student2: 1
Student3: 2
Student4: 3
Student5: 4

Multi-Threading

  • Multitasking is a feature that allows your system to run two or more programmes at the same time. Multithreading is a specialised kind of multitasking. Multitasking may be divided into two types: process-based and thread-based.
  • Process-based multitasking manages the execution of many applications at the same time. Thread-based multitasking is concerned with the multiprogramming of similar software parts.
  • Multithreaded applications are not supported by C++ by default. Instead, it relies only on the operating system to provide this functionality.

Related Topics

Timsort Implementation Using C++

Timsort Implementation Using C++ The Timsort is a stable sorting algorithm that uses the idea of merge sort and insertion sort. It can also be called a hybrid algorithm of insertion...

3 minutes read.

Roadmap to C++ Programming

Introduction There are so many programming languages available in the market, but among them, C++ is something that never lost its charm. It has a powerful impact on the programming world....

4 minutes read.

C++ Maximum Index Problem

Given an array A[] of positive integers. We will find the maximum of (j-i) such that i and j are the indexes of A[] and A[i] <= A[j], i<=j For...

5 minutes read.

C++ Structs

We frequently encounter scenarios in which we must store a bunch of data, whether of comparable or dissimilar data kinds. Arrays are used to hold a group of data of...

6 minutes read.

Different Ways to Compare Strings in C++

This section will go over the many methods for comparing strings in the C++ programming language. The string comparison checks if the first string is equal to another string. HELLO...

6 minutes read.

Palindrome using For loop in C++

A palindrome is a word, number, phrase, or other sequence of letters that reads the same backward as forward, such as 101 or MOM. Like other programming languages, C++ also allows...

6 minutes read.

Add two numbers represented by two arrays in C++

The array stores a number in such a way that each digit of the number is represented by an array element. As an example, The array number 147 is 1,4,7. To add...

3 minutes read.

Bit Manipulation in C++

The high-level language in which we communicate is not understood by the computer. As a result, there existed a standard mechanism for understanding any instruction sent to the computer. At...

5 minutes read.

Multiple Inheritance

C++ Multiple Inheritance Multiple inheritance is such an inheritance in which a derived class inherits properties of more than one base class.     C++ Multiple Inheritance Example In this example, two base classes Square and...

2 minutes read.

Inheritance in C++ vs Java

Just like we inherit traits from our parents, object-oriented programming has a concept called inheritance. In terms of object-oriented programming, a class's traits and behaviours, or its data and methods,...

4 minutes read.

C++ Program For FCFS (First Come First Serve)

The most basic scheduling technique is FCFS, often known as "FIFO (First In, First Out)". In this procedure, the first one is utilized and executed first, while the second one...

4 minutes read.

C++ add two numbers using the function

Here we will learn how to add two numbers by creating function in C++. Let’s learn this with help of example. Code: - #include <iostream> using namespace std; int add_two_no(int a, int b); int main(){   int...

1 minute read.

C++ Exception Handling

Exception is an unexpected problem that occurs at program run time. This problem might include condition such as division by zero, running out of memory space, array out of bonds, etc....

2 minutes read.

Vector Size in C++

What are Vectors?  In the C++ programming language, vectors are run-time sequence containers representing arrays with variable sizes, which are contained within STL (Standard Template Library). They utilize contiguous storage spaces...

6 minutes read.

C++ Friend Functions

In C++, friends are special functions that are not a part of a class yet have access to its private and protected members. The friend keyword is used to declare...

4 minutes read.

Virtual Functions and Runtime Polymorphism in C++

In this tutorial, we will explore more on virtual functions and runtime polymorphism in the most useful language C++. A virtual function is a member function with the keyword virtual used...

6 minutes read.

Priority Queue in C++

Priority Queue in C++ Introduction: We have already come across Queues by concluding that they are linear data structures that follow FIFO (First-In-First-Out) approach. We had also discussed the syntax of queues...

4 minutes read.

C++ Try-Catch

Every useful program will eventually encounter unexpected outcomes. By entering data that are incorrect, users might create mistakes. Sometimes the program's creator didn't consider all of the options or was...

7 minutes read.

Bitwise Operator vs Logical Operator

Bitwise Operator  Bitwise operators perform operations bit by bit on bits.The value is converted to abinary during operations like addition, subtraction, division, and so on. These operations are carried out at the...

3 minutes read.

Passing by Reference Vs. Passing by the pointer in C++

 Passing by Reference Vs. Passing by the pointer in C++ Throughout C++, it can transfer parameter values except by pointers or through referring to a function. For both cases, we have...

3 minutes read.