Monday, April 8, 2024

Features of c++


Remaining Features of c++:

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

some remaining fatures are as follows:

6.case-Sensitive:

Obviously C++ is a case-touchy programming language. For instance, cin is utilized to take input from the information stream. Yet, if the "Cin" won't work. Different dialects like HTML and MySQL are not case-delicate dialects.

7.Compiled Based:

C++ is a compiler-based language, in contrast to Python. That is C++ programs used to be aggregated and their executable record is utilized to run them. C++ is a moderately quicker language than Java and Python.

8.Dynamic Memory Allocation:

At the point when the program executes in C++ then the factors are designated the dynamical pile space. Inside the capabilities, the factors are distributed in the stack space. Ordinarily, We don't know ahead of time how much memory is expected to store specific data in a characterized variable and the size of required memory still up in the air at run time.

9.Memory Management:
  • C++ permits us to dispense the memory of a variable or a cluster in run time. This is known as Powerful Memory Designation.
  • In other programming dialects, for example, Java and Python, the compiler naturally deals with the recollections dispensed to factors. Yet, this isn't true in C++.
  • In C++, the memory should be de-dispensed progressively apportioned memory physically after it is of no utilization.
  • The allotment and deallocation of the memory should be possible utilizing the new and erase administrators individually

Example:

// 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 Treating:
Multithreading is a specific type of performing various tasks and performing various tasks is a component that permits your framework to simultaneously execute at least two projects. As a general rule, there are two kinds of performing various tasks: process-based and string based.
Process-based performing various tasks handles the simultaneous execution of projects. String based performing multiple tasks manages the multiprogramming of bits of a comparable program.
A multithreaded program contains at least two sections that will run simultaneously. Each piece of such a program is named a string, and each string characterizes a different way of execution.
C++ contains no inherent help for multithreaded applications. All things being equal, it depends completely upon the operating system to supply this component.
Example:

// 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:



No comments:

Post a Comment

last post

C language Vs C++ language in 2024

Popular Posts