Tutorial Study Image

Introduction to C++


July 17, 2022, Learn eTutorial
1570

C ++ is a general-purpose programming language developed as an extension of the C language using an object-oriented paradigm. This is an imperative compiled language. C ++ is a medium-level language with the advantage of being able to program low-level applications (kernels, drivers) and even high-level applications (games, desktop apps, GUIs, etc.). The basic syntax and code structure of  C and C ++ are the same.

The similarities between C and C ++ are:

  • The syntax for both languages is similar.  
  • The code structure for both languages is the same.  
  • The combination of both languages is similar.  The fundamental syntax is nearly the same. Almost all C operators and keywords exist in C ++ and do the same. 
  • The grammar of C ++ is a little more advanced than C, but the basic grammar is the same. 
  • Both basic memory models are very close to the hardware. 
  • The terms stack, heap, file space, and static variables are the same in both languages.

Differences between C and C++ are 

C C++
Between 1969 and 1973 Dennis Ritchie is the one who developed the C language. 1. Bjarne Stroustrup developed c++ in 1979.
Polymorphism, encapsulation, and inheritance are not supported by C and object-oriented programming is not supported by C. 2. Being an object-oriented programming language, C ++ supports polymorphism, encapsulation, and inheritance.
The subset of C ++ is C 3. C ++ is considered as a superset of C.
The C contains 32 keywords. 4. C ++ contains 63 keywords.
For code development, C supports procedural programming. 5. Since c++ supports both procedural and object-oriented programming paradigms C ++ is known as a hybrid language.
Being a procedural programming language, dataand functions are separatedby C. 6.In C++, dataand functions are encapsulated together intheform ofobjects.
Information hiding is not at all supported by C, 7.The data is hidden by encapsulation so that the data structures and operators are used as intended.
C supports built in datatypes and C is a functional language Built-in and user-defined data types are supported in C ++ and it is an object-driven language.
C is known as a functional programming language because C is a procedural programming language. C ++ is an object-driven language because it is object-oriented programming.
In C, the overloading of functions and operators is not supported. C ++ supports function and operator overloading
Namespace feature does not exist in C Namespaces are used in C ++ to avoid name collisions.
The header file used by the C is stdio.h. The header file used in C ++ is iostream.h.
Reference variables are not supported in C and it does not support virtual and friend features Reference variables are supported in C ++ and it supports Virtual and friend functions
C mainly focuses on the method or process. C ++ mainly focuses on data, not methods or procedures.
The C provides the malloc () and calloc () functions for dynamic memory allocation, and the free () function for deallocating memory. C ++provides new memory allocation and memory allocation operators.

Why C++?

C ++ is one of the most popular programming languages in the world and it is found in today's operating systems, graphical user interfaces, and embedded systems.   C ++ is an object-oriented programming language that gives programs a well-defined structure and allows code reuse, reducing development costs.  Moreover, it is portable and can be used to develop applications that are adaptable to multiple platforms.   C ++ is fun and easy to learn and one important feature of   C ++ is it is so similar to C # and Java that it makes it easy for programmers to switch to C ++ and vice versa.

Key Features of C++

Key Features of C++
  1. It is simple: It is a simple language in that it contains a comprehensive library support system, a wide range of data types, and the ability to decompose programs into logical units and components.
  2. Platform Dependent but Machine Independent: Although C++ executables are machine independent, they are not platform independent.For example, programs generated for Linux won't work on Windows
  3. It is a mid-level language: It is a mid-level language since we can program systems (drivers, kernels, networking, etc.) and create extensive user applications with it (Media Players, Photoshop, Game Engines, etc.)
  4. It has rich library support: That includes both third-party libraries (like the Boost libraries) and standard built-in data structures, algorithms, etc. for quick and efficient development. The C++ language offers a large number of built-in functions to rich library developers. This expedites development and saves time.Let's examine a few of the C++ header files and the features they offer.
    • <iostream>:  it contains the standard input and output functions of c++
    • <iomanip>: Contains data stream formatting stream, manipulators.
    • <cmath>: include functions from the math library.
    • <cstdlib>: Features utilities for converting numbers to text and vice versa, allocating memory, generating random numbers, and other useful features.
    • <ctime>: Time and date manipulation functions are included.
    • <fstream>: Functions that perform input from files on disc and output to files on disc are included.
    • <memory>: Contains classes and functions used by the C++ Standard Library to allocate memory to the C++ Standard Library containers
    • <iterator>: Classes for gaining access to data stored in C++ Standard Library containers are present. 
    • <algorithm>: Provides tools for working with data stored in C++ Standard Library containers.
  5. Execution speed: C++ applications run extremely quickly. It is a highly procedural compiled language. Newer languages contain more built-in default features like garbage collection, dynamic typing, etc. That will slow down how quickly a program is executed as a whole. It is incredibly quick because C++ doesn't have any additional processing overhead like this. Due to its quick compilation and execution, C++ is a fast language. Additionally, it offers a huge selection of data types, functions, and operators.
  6. Direct Memory-Access and pointers: C++ has pointer functionality that enables users to directly alter storage addresses. Low-level programming is made easier by using this.
  7. Object Oriented: One of the language's key features that distinguish it from C is that it is object-oriented. The support for object-oriented programming in C++ makes programs flexible and manageable. Large-scale applications can be also created.
  8. Memory management: Dynamic memory allocation is supported by C++. The RAM that has been allocated can always be freed. Additionally, C++ has dynamic memory management strategies.
  9. Pointers: The address of one variable is stored in a variable called a pointer. A variable's memory location is indicated via a pointer. Pointers are supported by C++, which also offers numerous solutions to issues that call for memory access. 
  10. It is compiler-based: C++ is a programming language that uses a compiler. None of the C++ programs can be run without compilation. The C++ program is first compiled by the compiler before being run.

History of C++

A computer scientist named Bjarne Stroustrup started working on "C with Classes," which is a superset of C, in 1979 at Bell Labs. While working on his Ph.D. Thesis, he came across this language Simula and found out that it had features that were helpful for large software implementations, but it was slow. Then, he set out to create a language that was as quick and effective as C while also having Simula-like features.

In 1982, he began developing a successor to “C with Classes” and named it “C++”, “++” being the increment operator. Along with that, there were many other features added, including virtual functions, single-line comments, references, constants, and operator and method overloading.