Introduction:
C++ is the first object oriented programming language used universally as an advanced version of C language. Many features such as Inheritance, Class & Object, Polymorphism(Function overloading) etc are introduced in C++ which are not available in C Language.
There are many differences between C & C++ few are mentioned below:
Difference between C & C++:
C | C++ |
C supports procedural programming paradigm for code developmen | C++ supports both procedural and object oriented programming paradigms; therefore C++ is also called a hybrid language. |
Follows top-down approach. | Follows bottom up approach. |
C is a subset of C++. It cannot run C++ code. | C++ is a superset of C. C++ can run most of C code while C cannot run C++ code. |
Function-driven language | Object-driven language |
Low-level language | Middle-level language |
C requires one to declare all the variables at the top of the program. | In C++, the variables can be declared anywhere in the program before use. |
The default header file used in C language is stdio.h | The default header file used in C++ is iosteam.h |
The features which are supported in C++ and not available in C Language:
Functions inside Structure:
In case of C++, functions can be used inside a structure while structures cannot contain functions in C.
Classes and Objects:
Class is a user defined datatype which contains member variables and member functions.
Object is a instance of defined class which helps to access member variable and member functions of the class.
We can define as many objects as we can for one class.
Function Overloading:
Function overloading is also known as a Polymorphism. Function overloading enables programmer to use same function name for multiple time(with different definition) through out the program.
Inheritance:
Inheritance is the capability of one class to acquire properties and characteristics from another class. The class whose properties are inherited by other class is called the Parent or Base or Super class. And, the class which inherits properties of other class is called Child or Derived or Sub class.
Constructor and Destructor:
A class constructor is a special member function of a class that is executed whenever we create new objects of that class. Constructor has the same name as class name.
A destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class. Destructor also has the same name as class name but only declared with tilde sign (~) before the declaration.
C++ has many other features such as namespace, exception handling, reference variable etc. More detailed information will be covered in upcoming articles.