The Wayback Machine - https://web.archive.org/web/20240726073341/https://www.geeksforgeeks.org/features-of-cpp/
Open In App

Features of C++

Last Updated : 12 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

C++ is a general-purpose programming language that was developed as an enhancement of the C language to include an object-oriented paradigm. It is an imperative and compiled language. C++ has a number of features, including:

  • Object-Oriented Programming
  • Machine Independent
  • Simple
  • High-Level Language
  • Popular
  • Case-sensitive
  • Compiler Based
  • Dynamic Memory Allocation
  • Memory Management
  • Multi-threading

features of C++

1. Object-Oriented Programming

C++ is an Object-Oriented Programming Language, unlike C which is a procedural programming language. This is the most important feature of C++. It can create/destroy objects while programming. Also, It can create blueprints with which objects can be created. We have discussed the Object-Orient Programming Concepts in C++ in this article.

Concepts of Object-oriented programming Language:

2. Machine Independent

A C++ executable is not platform-independent (compiled programs on Linux won’t run on Windows), however, they are machine-independent. Let us understand this feature of C++ with the help of an example. Suppose you have written a piece of code that can run on Linux/Windows/Mac OSx which makes the C++ Machine Independent but the executable file of the C++ cannot run on different operating systems.

3. Simple

It is a simple language in the sense that programs can be broken down into logical units and parts, has rich library support and has a variety of data types. Also, the Auto Keyword of C++ makes life easier.

Auto Keyword

The idea of the auto keyword was to form the C++ compiler to deduce the data type while compiling instead of making you declare the data type every freaking time. Do keep in mind that you cannot declare something without an initializer. There must be some way for the compiler to deduce your type.

Example:

C++




// C++ program to demonstrate
// working of auto keyword
  
#include <bits/stdc++.h>
using namespace std;
  
// Driver Code
int main()
{
  
    // Variables
    auto an_int = 26;
    auto a_bool = false;
    auto a_float = 26.24;
    auto ptr = &a;_float;
  
    // Print typeid
    cout << typeid(a_bool).name() << "\n";
    cout << typeid(an_int).name() << "\n";
    return 0;
}


Output: 

b
i

 

4. High-Level Language

C++ is a High-Level Language, unlike C which is a Mid-Level Programming Language. It makes life easier to work in C++ as it is a high-level language it is closely associated with the human-comprehensible English language.

5. Popular

C++ can be the base language for many other programming languages that supports the feature of object-oriented programming. Bjarne Stroustrup found Simula 67, the first object-oriented language ever, lacking simulations, and decided to develop C++.

6. Case-sensitive

It is clear that C++ is a case-sensitive programming language. For example, cin is used to take input from the input stream. But if the “Cin” won’t work. Other languages like HTML and MySQL are not case-sensitive languages.

7. Compiler Based

C++ is a compiler-based language, unlike Python. That is C++ programs used to be compiled and their executable file is used to run them. C++ is a relatively faster language than Java and Python.

8. Dynamic Memory Allocation

When the program executes in C++ then the variables are allocated the dynamical heap space. Inside the functions, the variables are allocated in the stack space. Many times, We are not aware in advance how much memory is needed to store particular information in a defined variable and the size of required memory can be determined at run time.

9. Memory Management

  • C++ allows us to allocate the memory of a variable or an array in run time. This is known as Dynamic Memory Allocation.
  • In other programming languages such as Java and Python, the compiler automatically manages the memories allocated to variables. But this is not the case in C++.
  • In C++, the memory must be de-allocated dynamically allocated memory manually after it is of no use.
  • The allocation and deallocation of the memory can be done using the new and delete operators respectively.

Example:

C++




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


Output: 

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

 

10. Multi-threading

  • Multithreading is a specialized form of multitasking and multitasking is a feature that allows your system to execute two or more programs concurrently. In general, there are two sorts of multitasking: process-based and thread-based.
  • Process-based multitasking handles the concurrent execution of programs. Thread-based multitasking deals with the multiprogramming of pieces of an equivalent program.
  • A multithreaded program contains two or more parts that will run concurrently. Each part of such a program is named a thread, and every thread defines a separate path of execution.
  • C++ doesn’t contain any built-in support for multithreaded applications. Instead, it relies entirely upon the OS to supply this feature.

Example:

C++




// C++ Program to implement
// the working of Multi-threading
  
#include <cstdlib>
#include <iostream>
#include <pthread.h>
  
using namespace std;
  
#define NUM_THREADS 5
  
// Function to print Hello with
// the thread id
void* PrintHello(void* threadid)
{
    // Thread ID
    long tid;
    tid = (long)threadid;
  
    // Print the thread ID
    cout << "Hello World! Thread ID, "
         << tid << endl;
  
    pthread_exit(NULL);
}
  
// Driver Code
int main()
{
  
    // Create thread
    pthread_t threads[NUM_THREADS];
    int rc;
    int i;
  
    for (i = 0; i < NUM_THREADS; i++) {
  
        cout << "main() : creating thread, "
             << i << endl;
  
        rc = pthread_create(&threads;[i],
                            NULL,
                            PrintHello,
                            (void*)&i;);
  
        // If thread is not created
        if (rc) {
            cout << "Error:unable to"
                 << " create thread, "
                 << rc << endl;
  
            exit(-1);
        }
    }
  
    pthread_exit(NULL);
}


Output:

 

This tutorial assumes that you are working on Linux OS and we are going to write a multi-threaded C++ program using POSIX. POSIX Threads or Pthreads provide API which is available on many Unix-like POSIX systems such as FreeBSD, NetBSD, GNU/Linux, Mac OS X, and Solaris. 



Previous Article
Next Article

Similar Reads

Multimedia Systems with features or characteristics
What are Multimedia Systems: A multimedia system is responsible for developing a multimedia application. A multimedia application is a bundle of different kinds of data. A multimedia computer system is one that can create, integrate, store, retrieve delete two or more types of media materials in digital form, such as audio, image, video, and text i
3 min read
Features and Use of Pointers in C/C++
Pointers store the address of variables or a memory location. Syntax: datatype *var_name; Example: pointer "ptr" holds the address of an integer variable or holds the address of memory whose value(s) can be accessed as integer values through "ptr" int *ptr; Features of Pointers: Pointers save memory space.Execution time with pointers is faster beca
2 min read
Features of Cassandra
Apache Cassandra is an open source, user-available, distributed, NoSQL DBMS which is designed to handle large amounts of data across many servers. It provides zero point of failure. Cassandra offers massive support for clusters spanning multiple datacentres. There are some massive features of Cassandra. Here are some of the features described below
3 min read
What Are Azure Data Security Features?
Data security is a huge topic and it's one of the most important types of security in space today. Lots of hackers and world governments are trying to break into databases because Data has got a lot of financial and other value. Azure has a multi-layer view of security that you can't just have one single fence around your data. You need to have mul
6 min read
Fundamental Features of MQTT
Prerequisite - Message Queue Telemetry Transport Protocol (MQTT) Quality of Service (QoS) Levels : Quality of Service is a level of agreement between the client and the broker. This level helps the clients to ensure the reliability for the delivery of their message. There are 3 QoS levels : QoS 0: At most Once - When message is published with QoS l
4 min read
Features of C++ 17
C++17 enables writing simple, clearer, and more expressive code. Some of the features introduced in C++17 are: Nested NamespacesVariable declaration in if and switchif constexpr statementStructured bindingsFold ExpressionsDirect list initialization of enumsNested Namespaces Namespaces are a very convenient tool to organize and to structure the code
14 min read
Fundamental Features of MQTT | Set 2
Prerequisites – Message Queue Telemetry Transport Protocol (MQTT) Fundamental Features of MQTT | Set 1 Retained Messages : In MQTT, when clients publish messages to the broker, the retain flag is by default false. In such a case, the broker simply delivers the message to the intended subscribed client and then discards the message. But if the subsc
3 min read
Fundamental Features of MQTT | Set 3
Prerequisites – Message Queue Telemetry Transport Protocol (MQTT) Fundamental Features of MQTT | Set 1 Fundamental Features of MQTT | Set 2 Last Will and Testament : In MQTT, publisher client publishes messages on specific topic to Broker. The broker then publishes these messages to clients subscribed to that topic. If the publisher/subscriber clie
2 min read
Fundamental Features of MQTT | Set 4
Prerequisites – Message Queue Telemetry Transport Protocol (MQTT)Fundamental Features of MQTT | Set 1Fundamental Features of MQTT | Set 2Fundamental Features of MQTT | Set 3 Keep-Alive Messages : In MQTT, when clients and brokers are communicating with each other, then connection established between two can be lost due to various reasons like - One
3 min read
Microsoft Azure - Top Azure Kubernetes Service Features
Microsoft Azure Kubernetes Service provides integration of the Kubernetes Engine to Microsoft Azure. It is also known as the Azure Kubernetes Services. In this article, we will discuss the top properties of Azure Kubernetes Services. 1. AKS Managed Identity The first thing that Azure Kubernetes Service needs is an identity to create resources like
3 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg