Monday, August 22, 2011

Major Difference between C n C++, Question of a HR....

Major 10 differences
C++, as the name suggests is a superset of C. As a matter of fact, C++ can run most of C code while C cannot run C++ code. Here are the 10 major differences between C++ & C…
1. C follows the procedural programming paradigm while C++ is a multi-paradigm language(procedural as well as object oriented)
In case of C, importance is given to the steps or procedure of the program while C++ focuses on the data rather than the process.
Also, it is easier to implement/edit the code in case of C++ for the same reason.


2. In case of C, the data is not secured while the data is secured(hidden) in C++
This difference is due to specific OOP features like Data Hiding which are not present in C.
3. C is a low-level language while C++ is a middle-level language (Relatively, Please see the discussion at the end of the post)
C is regarded as a low-level language(difficult interpretation & less user friendly) while C++ has features of both low-level(concentration on whats going on in the machine hardware) & high-level languages(concentration on the program itself) & hence is regarded as a middle-level language.
4. C uses the top-down approach while C++ uses the bottom-up approach
In case of C, the program is formulated step by step, each step is processed into detail while in C++, the base elements are first formulated which then are linked together to give rise to larger systems.
5. C is function-driven while C++ is object-driven
Functions are the building blocks of a C program while objects are building blocks of a C++ program.


6. C++ supports function overloading while C does not
Overloading means two functions having the same name in the same program. This can be done only in C++ with the help of Polymorphism(an OOP feature)
7. We can use functions inside structures in C++ but not in C.
In case of C++, functions can be used inside a structure while structures cannot contain functions in C.
8. The NAMESPACE feature in C++ is absent in case of C
C++ uses NAMESPACE which avoid name collisions. For instance, two students enrolled in the same university cannot have the same roll number while two students in different universities might have the same roll number. The universities are two different namespace & hence contain the same roll number(identifier) but the same university(one namespace) cannot have two students with the same roll number(identifier)
9. The standard input & output functions differ in the two languages
C uses scanf & printf while C++ uses cin>> & cout<< as their respective input & output functions
10. C++ allows the use of reference variables while C does not
Reference variables allow two variable names to point to the same memory location. We cannot use these variables in C programming.
  • C does not have any classes or objects. It is procedure and function driven. There is no concept of access through objects and structures are the only place where there is a access through a compacted variable. c++ is object oriented.
  • C structures have a different behaviour compared to c++ structures. Structures in c do not accept functions as their parts.
  • C input/output is based on library and the processes are carried out by including functions. C++ i/o is made through console commands cin and cout.
  • C functions do not support overloading. Operator overloading is a process in which the same function has two or more different behaviours based on the data input by the user.
  • C does not support new or delete commands. The memory operations to free or allocate memory in c are carried out by malloc() and free().
  • Undeclared functions in c++ are not allowed. The function has to have a prototype defined before the main() before use in c++ although in c the functions can be declared at the point of use.
  • After declaring structures and enumerators in c we cannot declare the variable for the structure right after the end of the structure as in c++.
  • For an int main() in c++ we may not write a return statement but the return is mandatory in c if we are using int main().
  • In C++ identifiers are not allowed to contain two or more consecutive underscores in any position. C identifiers cannot start with two or more consecutive underscores, but may contain them in other positions.
  • C has a top down approach whereas c++ has a bottom up approach.
  • In c a character constant is automatically elevated to an integer whereas in c++ this is not the case.
  • In c declaring the global variable several times is allowed but this is not allowed in c++. 

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...