What are the differences between C and C++

 C is an imperative (procedural), structured paradigm language whereas C++ is multi-paradigm: procedural, functional, object-oriented and generic. Both are high-level, abstract languages. While C's design provides constructs that map efficiently to machine code instructions, C++ is more abstract, relying heavily upon object-oriented principals. However, both are equally capable of producing highly-efficient machine code programs. C++ derives almost directly from C thus everything you can do in C you can do in C++ with relatively minor alterations to the source. C++ was originally called C with Classes and that pretty much sums up the main difference between the two languages. However, there are many subtle differences.

One key difference between C and C++ is in the struct data type. In C, a struct can only contain public data members (with no methods). In C++, a struct is similar to a class, combining data and the methods that operate upon that data into a single entity (an object). The only difference between a C++ struct and a C++ class is that class members are private by default whereas struct members are public by default.

Another key difference is that because C++ is object oriented, there is much less reliance upon the programmer to manage memory. Each object takes care of its own memory allocations (including embedded objects), thus the programmer simply creates and destroys objects as needed. Thus C++ is much easier to work with, especially with regards to highly-complex hierarchical structures, but is every bit as efficient as C.

Both languages are highly popular and there are few architectures that do not implement suitable compilers for both. Thus they are both highly portable. However, the object oriented approach to programming gives C++ a major advantage over C in terms of code re-usability, scalability and robustness.

No comments: