C Vs C++
C and C++ are computer programming languages that are used to write programs to communicate with computer. The Difference Between C and C++ is one of the most commonly asked question in technical interviews . The C language was originally developed by Dennis Ritchie at AT & T Bell Labs between 1969 and 1973. C++ was developed by Bjarne Stroustrup at Bell Labs starting in 1979.
In terms of basic orientation, C language basically supports structured procedural programming . While C++ supports that as well as object oriented programming, generic programming, and metaprogramming (carrying out arbitrary computation at compile time). Basically, C++ was invented to manage complexity that C could not handle. C++ was originally named C with Classes , as it had been based on C. It was renamed C++ in 1983. In general, everything that exists in C is supported in C++. This means that you can not only use the new features introduced with C++ but can also use the power and efficiency of C language. Obviously the opposite is absolutely false. So, we can say C++ is a superset of C and contains all the features of C language. Still there are some difference between C and C++.
Here is a list of differences between c and c++:
C | C++ |
File extension .c | File extension .cpp |
Default header file is stdio.h | Default header file is iosteam.h |
Structural or Procedural programming language. | Object Oriented programming language. |
Functions are the fundamental building blocks. | Objects are the fundamental building blocks. |
Top down approach is used in Program Design. | Bottom up approach adopted in Program Design. |
Call main() Function through other Functions | Cannot call main() Function through other functions. |
Supports only Pointers. | Supports both pointers and references. |
Focuses on method or process rather than data. | Focuses on data rather than method or procedure. |
Data and functions are separate and free entities. | Data and functions are encapsulated together in form of an object. |
Declare all the variables at the top of the program. | Declared anywhere in the program before use. |
Multiple Declaration of global variables are allowed. | Multiple Declaration of global variables are not allowed. |
Does not provide String or Boolean data types. It supports primitive & built-in data types. | Provides Boolean or String data types. It supports both user-defined and built-in data types. |
Does not have inline function. | Has inline function. |
Does not support reference variables. | Supports reference variables. |
Data is not secured. | Data is hidden and can't be accessed by external functions. |
No namespace features present | Namespace feature present for avoiding collision |
Does not support for virtual and friend functions. | Supports virtual and friend functions. |
Does not support function overloading. | Supports function overloading. |
Does not provide direct support for error handling . Can be done by using some other functions. | C++ supports exception handling. Done by using try and catch block. |
Does not support Encapsulation. Data and functions are separate and free entities. | Supports encapsulation. Data and functions are encapsulated together in form of an object. |
Concept of virtual functions is not present. | Offers the facility of using virtual functions. |
NEXT.....Difference Between a Resume and CV