Because of both it's low-level and high-level features, C++ is still one the most popular and widely-used language today. The high-level features were the result of enhancements to the earlier C thus retaining the low-level features. So if C++ is just an enhanced version of C, where do the differences lie? To answer this question, C++ was enhanced to exclude some of the C principles and to include some the features unknown to a C compiler.
Syntax Change
The first and very basic difference between the two languages is the slight change in syntax of some of the libraries.
Library & Linking
C++ has a larger library than C. For example, to compile a math-extensive program in gcc you have to separately link the math library for basic math functions in C. On the other hand you don't have to do explicit linking in C++.
Memory Allocation/DeAllocation
In C memory allocation for both arrays and elements is done through malloc. Also, inorder to deallocate the memory, it has to be done using free. In C++ memory allocation is done using new operator. Similarly, delete is used to free the memory.
Function Declaration
You need not explicitly declare a function in C. On the contrary, a C++ function need to be declared before use.
Structs
In C 'struct' keyword has to be explicitly included when declaring an instance. This has not to be done in C++.
Boolean Type
There is no primitive boolean data type in C. On the other hand, C++ has a primitive "bool" data type.
Library
The first and very basic difference between the two languages is the slight change in syntax of some of the libraries.
Summary
C++ could be seen as a better and more capable C in view of it's capability of having low-level and high-level features.
0 comments:
Post a Comment