Now here in this tutorial, I’ll explain all the top level main difference between c and c++ in oops.
In my previous tutorials, I’d explained many tutorials on OOPS Concepts, Asp.net, jQuery and JavaScript here.
C++ is an extension of C language. 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.
C and C++ are no more language for writing compilers and other languages, these general purpose languages are used worldwide in every field.
C++ expressions are the same as C expressions and most of the C Programs can be compiled in C++ compiler. Also mostly all C operators are valid in C++.
Difference: Understanding the Top 10 Main Difference Between C And C++
Following are the list of best main difference between C and C++.
Sr. | C | C++ |
---|---|---|
1. | C programming language was designed by Dennies Ritchie in 1972 at Bell Laboratories | C++ was designed by Bjarne Stroustrup in 1983 at Bell Laboratories |
2. | C is Procedural-Paradigm Language | C++ is Multi-Paradigm Language, that means procedural, functional as well as object oriented programming |
3. | C is a low-level programming language Note: See update below |
C++ is a middle-level programming language Note: See update below |
4. | C does not support Operator Overloading | The concept of Operator Overloading is supported by C++ |
5. | C does not directly support Polymorphism. Note: We can achieve it by using struct in C | The concept of Polymorphism is supported by C++. Polymorphism is the one of the important feature of OOP |
6. | C does not directly support Inheritance. Note: We can achieve it by using struct in C | C++ supports Inheritance in its programs |
7. | C does not support Namespace feature in its program | C++ uses Namespace feature in programs to avoid “Name Collision” |
8. | C does not directly support Virtual Function. Note: We can achieve it by using struct in C | The concept of Virtual Function is supported by C++ |
9. | In C, Multiple Definition of Global Variables are allowed | In C++, Multiple Definition of Global Variables are not allowed |
10. | C uses top-down approach in its program design. We can designed Note: See update below |
C++ uses bottom-up approach in its program design Note: See update below |
11. | C applications are faster to compile and execute as compared to C++ applications | C++ applications are slidely slower due to more complex language as compared to C applications but the performance of C++ and C are equal (if we implement them correctly), since compilers are mature |
12. | Mapping between Data and Function is difficult and complicated in C | Where as in C++, Mapping between Data and Function can be done using “Objects” |
13. | In C, scanf() function is used for Input printf() function is used for Output |
In C++, Cin>> is used for Input Cout<< is used for OutputNote: You can use them but the major problem is that the format specifiers did not match the arguments and resulted in crashes etc. For example, char ch; scanf(“%s”,&ch); //may be leads to a crash |
14. | C supports built-in and primitive data types | C++ supports both built-in and user defined data types |
15. | In C, Exception Handling is not present | In C++, Exception Handling is done with Try and Catch block |
16. | C requires all the variables to be defined at the starting of a scope | C++ allows the declaration of variable anywhere in the scope meaning at time of its first use in program |
17. | In C, malloc() and calloc() functions are used for Memory Allocation and free() function for Memory Deallocating | In C++, new and delete operators are used for Memory Allocating and Deallocating respectively
Note: We can still use malloc(), calloc() and free() functions for plain old data types, that is data that doesn’t need constructors or destructors to be called. |
UPDATES:
Point 3: Both C and C++ are “high level” programming languages but they are always mixed opinions. Some peoples like to call it as a “middle-level or high-level” language. But there’s really no determining factor behind the level of a programming language. Essentially, we’re making all the changes at the machine level, right? C is on a lower level of abstraction “relatively” as compared to C++. Hence, referred to here as “low-level”.
Point 10: C programs can be designed as bottom-up. C++ program can be designed as top-down. But In C, there are no objects and it is procedural, that means start from first statement of main function and goes to bottom statement of main function, that is why i refereed to as a “top-down”. Where as In C++, We can use same strategy, but mainly C++ is known for object oriented programming, that’s why i refereed to as a “bottom-up”.
Hi Mayank,
Thank you for such an insightful article. I would greatly appreciate if you also publish a similar article on “differences between C++ and Java”.
Keep up the good work!
Hello,
Thanks for your interest and I welcome your suggestion and added your requested point to my list. You will see that soon! I’ll also inform you here with the link.
Very Good. All of our developers who learnt C and C++ should know these differences. Thank you for your post to prepare well for attending fake interviews in companies to disappoint them.