Advantages Of C++

In this blog, you will learn the advantages of C++ over C.  In 1979, when Bijarne Stroustrup was working on his PhD thesis, one of the languages Stroustrup had the opportunity to work with was called simula (simulation language). Later, Stroustrup had an opportunity to work with the object oriented programming paradigm. Shortly after this, he began working on "C with Classes", which as the name implies was meant to be a superset of the C language.
 
His goal was to integrate object-oriented programming in the C language, which was and still is a language well-respected for its portability without sacrificing speed or low-level functionality. His language included classes, basic inheritance, inlining, default function arguments, and strong type checking in addition to all the features of the C language.

The first C with classes complier called C-Front which was derived from cpre. Cpre was later abandoded in 1993. In 1983, the name of C with classes changed to C++.The advantages of C++ are,
  1. C++ has rich foundation library.
  2. C++ is a highly portable language and its is used for multi platform app devolpment
  3. And also C++ is a object oriented programming language it also has classes,objects where as in c there is no classes.
  4. C++ is a powerful, efficient and fast language. It finds a wide range of applications – from GUI applications to 3D graphics for games to real-time mathematical simulations.
Complitation in C++

During complitation in C++, it approaches from the bottom whereas in C,  the approach goes from top to bottom.

Data Types in C++

There are four types of data in C++,
  1. User defined data type
  2. Derived data type
  3. Built in data type
  4. Void data type
User defined data type

In the user defined data type, the data type is defined by the user . For example -
  1. class
  2. structure
  3. enumeration
Derived data type

In the derived data type, this data type contains some additional information about the data. For example -
  1. pointer
  2. array
  3. function
Built in data type

In the built in data type, the data types are predefined. For example -
  1. Intenger
  2. fFoat and also variable data types
Void data type

Void data types return nothing. It's used to define empty arguments. Void pointer is also used to declare the generic pointer.

Generic Pointer

Generic pointer means - it can't point to any data, so it can't be dereference.
 
Next, we are going to see about call by address and call by value and also unique feature to C++ known as Referenced data type(this is not in C++).

Call by reference

In this call by reference the value changed in the formal parameter changes also changed in actual parameter. In this mechansim the address of the variable is passed hence changes in the formal parameter it changes over the actual parameter; this mechanism is explained in the given example

Call by value

In this call by value mechanism,the value is changed in the formal parameter but not changed in the actual parameter because in this mechanism only the value is passed but whereas in the call by reference the address is passed so the value is changed in the formal parameters. This mechanism is explained in the given example
  1. void sample(int a) {  
  2.     a = a + 10;  
  3. }  
  4. main() {  
  5.     int x = 100;  
  6.     sample(x);  
Refernced data type

In this referenced data type, it provides an alternate name for previously defined variables. Refernced data type is only in C++,  not in C, for example
  1. int x=10;  
  2. int r=&x;  
Here, r is a referenced variable that shares the memory of the previous variable. Here, the variable shares the same location. The reference variable must be initalized at the time of the declaration.
  1. void sample(int & a) {  
  2.     a = a + 10;  
  3. }  
  4. main() {  
  5.     int x = 100;  
  6.     sample(x);  
  7. }  
Advantage of using referenced variable is that it saves memory.