×

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

Private Inheritance in C++

Private inheritance is an inheritance in object-oriented programming (OOP) languages where a subclass derives from a superclass. Still, the derived class does not inherit the public and protected members of...

7 minutes read.

Constructor Overloading in C++

A Constructor is a class member function that is used to initialize the class's objects. Constructors have no return type and are called automatically when an object is formed. Constructor Characteristics Constructors...

3 minutes read.

C++ Program: Matrix Multiplication

Matrix Multiplication in C++ What is a Matrix? A matrix is a set of numbers in the form of rows and columns forming a rectangular array. It includes numbers, which are often...

4 minutes read.

Classes and Objects in C++

When it comes to object-oriented programming, objects are the basic building blocks. Memory is taken up by objects, which contain data and methods or functions that operate on it. On...

3 minutes read.

Data Hiding in C++

C++ : High-performance apps can be made using the cross-platform language C++. Bjarne Stroustrup created C++ as an addition to the C language. Programmers have extensive control over memory and system...

3 minutes read.

C++ Program to find largest subarray with 0 sum

Write a program to find the largest subarray that has a sum zero. The array contains positive and negative numbers. Print the length of the max subarray whose sum turns...

4 minutes read.

C++ Tricks for Competitive Programming

If you are interested in Computer science or Information technology, you must have heard about competitive programming. Competitive programming is a way to improve your problem-solving skills. There are various...

7 minutes read.

Is it fine to write void main() or main() in C/C++?

In C programming language: The default function return type in the C programming language is "int," which implies that main() will always return an integer value. In C, the void main()...

3 minutes read.

C++ Ternary Operator

In this tutorial, we'll learn about the C++ ternary operator and how to utilise it to manage the program's flow using examples. Ternary Operator: The if-else statement and the conditional operator use...

3 minutes read.

Dynamic _Cast in C++

C++ is one of the most powerful programming languages. We can write object-oriented and structured programming with the help of C++. In this article, we will learn about the dynamic...

3 minutes read.

Type difference of Character literals in C VS C++

Character literals in C: In C, a character literal is represented by a single character enclosed in single quotes, such as 'a' or 'b'. It is of type int. This means...

5 minutes read.

C ++ Program: Alphabet Triangle and Number Triangle

Alphabet Triangle and Number Triangle An alphabet triangle is a triangle that typically looks like a pyramid or other triangles like an isosceles triangle, a right-angled triangle consisting of similar or...

4 minutes read.

New Operator in C++

Dynamic memory allocation in C++ means manually allocating the memory by the developer duing run-time. The dynamic memory is allocated in the heap section of the RAM, whereas the static...

3 minutes read.

Difference between "int main( ) and int main(void)" in C/C++

int main( ) function In the C/C++ programming language, int main() indicates a function that returns an integer at the end of the program execution. In general, a value of '0' indicates...

3 minutes read.

C++ Encapsulation

The following two essential components are present in all C++ programmes: Functions are the parts of a programme that perform actions, and they are termed programme statements (code).Program data is the...

4 minutes read.

C++ Fibonacci Series

What is a Fibonacci series? A Fibonacci series or sequence is a very popular programming paradigm. The next element occurring in the N terms series is determined by the sum of...

2 minutes read.

Convex hull Algorithm in C++

The intersection of all convex sets containing a certain subset of a Euclidean space, or alternatively, the set of all convex combinations of points in the subset, defines the convex...

4 minutes read.

C++ Pointer

Pointer is a derived data type that stores the address of a variable. A pointer is used for memory management and dynamic memory allocation. Pointer works on the address of data rather than...

2 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++ | C Plus Plus While loop

In this article, we will discuss the C++ while loop with its syntax, use, key features, key points, pseudo code, and examples. What is the While Loop? The “while loop” is a...

4 minutes read.