Subscribe by Email


Friday, August 26, 2011

What are the fundamental differences between C and C++ ?

Developments in software technology continue to be dynamic. New tools and techniques are announced in quick succession. To build today’s complex software it is just not enough to put together a sequence of programming statements and sets of procedures and modules; we need to incorporate sound construction techniques and program structures that are easy to comprehend, implement and modify. Thus the languages C and subsequently C++ were born. Since C++ is an extended version of C it forms the superset of C.
Conventional programming uses languages like C (known as procedure-oriented programming (POP)). The problem is viewed as a sequence of things to be done such as reading, calculating and printing. A number of functions are written to accomplish these tasks. The primary focus is on functions. Object-oriented programming (OOP), using languages like C++ is an approach to program organization and development that attempts to eliminate some of the pitfalls of conventional programming methods by incorporating the best of structured programming features with several powerful new concepts.
Therefore, here we derive some basic differences between C and C++:

1. As we saw above, C follows the POP paradigm while C++ follows an OOP paradigm. So, in C the emphasis is on doing things whereas, C++ views problem in terms of objects involved rather than procedure for doing it. The emphasis is on data.
2. Data is given a second class status in C but, in C++ data is given all the priority.
3. In C global data are more vulnerable to an inadvertent change by a function whereas in C++ data is encapsulated or hidden so, secure.
4. C lacks data hiding features but C++ comes with options of data abstraction and encapsulation which makes data hiding possible.
5. C follows a top-down approach while C++ uses the bottom-up approach.
6. In C a number of functions are written to accomplish a task whereas in C++ programs are divided into what are known as objects and tied together using functions.
7. It’s not easy to add functions and data to the existing program in the case of C but it can be easily added wherever required in a C++ program.
8. C doesn’t support class concept but C++ does.
9. Structures are present in both C and C++, but behave differently. C structures do not support functions contained in them.
10. In C. input/ output processing is carried out by functions (scanf and printf). C++ uses console commands “cin” and “cout”.
11. Function overloading and operator overloading are not supported by C. So, it means polymorphism is absent in C. C++ supports polymorphism well.
12. C lacks “NAMESPACE” feature while C++ supports NAMESPACE which avoids name collisions.
13. References can be used in C++ but not in C.
14. C uses malloc() and free() commands for allocation and de-allocation of memory. C++ uses new and delete commands.
15. In C header file used in whereas it is for C++.
16. C++ programs take much more time for compiling as compared to C programs. For this reason C is commonly used.
17. C is a low-level language whereas C++ is an intermediate language.


No comments:

Facebook activity