Difference between C and C++
C++ is an improvement over C. C and C++ use a completely different approach. The main focus in C is on procedures(functions) whereas in C++ basically Classes and Objects are used. Due to increasing need of data security, a data hiding feature was also added to C++ by using access specifiers. C supports user defined data types i.e. struct, but it was unable to support functions. The classes in C++ support this feature. Some of the main differences between C and C++ are:
|
S.No. |
Feature |
C |
C++ |
|
1 |
Orientation |
Procedure Oriented |
Object Oriented |
|
2 |
Encapsulation |
Not Supported |
Supported |
|
3 |
Inheritance |
Not Supported |
Supported |
|
4 |
Function Overloading |
Not Supported |
Supported |
|
5 |
Access Specifier |
only public; (data hiding not supported) |
public, protected and private |
|
6 |
Operator Overloading |
Not Supported |
Supported (except. .* :: ?: ) |
|
7 |
Input-Output Library |
stdio.h |
iostream.h |
|
8 |
Input Statement |
scanf |
cin |
|
9 |
Output Statement |
Printf |
cout |
|
10 |
Approach |
top-down |
bottom-up |
|
11 |
Reference Variables |
Not Supported |
Supported |
|
12 |
Inline Functions |
Not Supported |
Supported |
|
13 |
Passing to a function |
Zero argument function can be called by passing arguments too |
Zero argument function can’t be called by passing arguments |
|
14 |
Type Casting |
Constant is automatically elevated |
Not elevated |