Difference Between C and C++: If you are learning to program or you are a computer science student, then it is important for you to know the difference between the two most widely used programming language C and C++. “What are the difference between C and C++” – is a common question in exams or sometimes in the campus recruitment. So, it is important for everyone to know the basic difference between C and C++. But before moving to the difference between C and C++ it is also important for you to know the basic history of both the languages. So, let’s start with the history of C and C++.
History of C language:
The history of C can be defined from the language ALGOL-60. It was developed in 1960. Then in 1963 CPL (Combined Programming Language) was developed and after that in 1967, BCPL (Basic Combined Programming Language) was developed by Martin Richards in Cambridge University which was completely based on CPL but with some new features. Then in 1969, a language called B was developed by Ken Thompson in Bell Labs but B and BCPL both were the typeless languages. So in 1972, C language was developed by Dennis Ritchie at AT&T Bell Labs in New Jersy, USA.
C language was developed by combining the features of ALGOL-60, BCPL and B and removing the drawbacks of them. The concept of data-type was introduced for the first time in the C language. In 1989 American National Standards Institute published C language officially and was named as ANSI-C. Then in 1990, this standard was got ISO certified. Then again in 1995 ISO released an extension for the internationalisation of C language.
History of C++ language:
C++ was developed by Bjarne Stroustrup in 1980 with C++’s predecessor known as “C with classes”. The concept of developing C++ came into the mind of Bjarne Stroustrup when he was working on a language called Simula in 1979, which was basically used in the simulation. He noticed that the concept of object-oriented programming can be added to the C language to make C language more powerful for the software development. Then he started working on the C language to add the concept of object-oriented programming without affecting the original features of C language. At that time he named this language as “C with classes”. Finally in 1983 C with classes was named as C++.
In C++, the “++” sign indicated that C++ is an extended and incremented version of the C language. Though C++ supports object-oriented features, it is not a purely object-oriented language like Java. Sometimes, it is called a hybrid language since it supports both object-oriented and procedural programming method. Since C++ is the extended version of the C language so all the compilers of C++ can run C programs easily without having any issue.
So we have discussed a very sort history of C and C++. Now let’s move on to the basic relation between C and C++ and after that, we will discuss all the major difference between C and C++ in a tabular form.
The basic relation between C and C++:
- Actually, C++ was derived from C language. So C++ is called as the superset of C language.
- Before naming it as C++, it was known as C with classes.
- The main difference between C and C++ is the addition of class and object concept. i.e. inheriting the class object into other class.
- Most of C programs can be compiled using C++ compiler.
- Expressions used in C++ are almost the same as the expression used in C language.
- All C operators used in C are valid in C++.
Difference between C and C++ in tabular form:
|C is a procedural language.||C++ is an object-oriented language.|
|No virtual functions are present in C.||The concept of virtual functions is used in C++.|
|Polymorphism is not possible in C.||Polymorphism is possible in C++.|
|Operator overloading is not possible.||Operator overloading is possible in C++.|
|C uses the top-down approach in program design.||C++ uses the bottom-up approach in program design.|
|Multiple declarations of global variables are allowed in C.||Multiple declarations of global variables are not allowed.|
|Functions scanf() and printf() are used for input and output in C programs.||Functions cin>> and cout<< are used for input and output in C++ programs.|
|The mapping between data and function is difficult and complicated in C.||In C++, the mapping between data and function can be done using objects.|
|In C, we can call the main() function through other function.||In C++, we can’t call main() function through other functions.|
|It required all the variable to be defined at the starting of the scope.||C++ allows the declaration of variables anywhere in the scope. i.e. anywhere before the first use.|
|The concept of inheritance is not available in C.||The concept of inheritance is available in C++.|
|In C, malloc() and calloc() functions are used for memory allocation and free() is used for deallocation.||In C++, new and delete operator are used for allocation and deallocation of memory respectively.|
|Exception handling is not possible in C.||C++ can handle the exception using Try and catch block.|
|C does not support namespace feature.||C does support namespace to avoid name collision.|