10 Major Differences Between C And C++

343

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.

Note: This is a relative difference. See updates at end of this post.

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.

MORE –

11. C++ supports Exception Handling while C does not.

C does not support it “formally” but it can always be implemented by other methods. Though you don’t have the framework to throw & catch exceptions as in C++.

(will add more..)

UPDATES (ref to comments)-

Praveen – some of them r telling ‘C’ is a middle level language…..tell me the correct type of level language….?

Answer-@praveen – I agree there are always mixed opinions about this one. Some even like to call it a 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? Now, as we increase the abstraction and move away from the machine-level, the level of the language increases. So, the level is nothing but the level of abstraction. So, most of the languages we use in applications today will have aspects of both machine-level and user-level. The two levels are machine-level & user(real world)-level while high & low levels are relative terms. Although, C is on a lower level of abstraction “relatively”- when compared to C++. Hence, referred to here as low-level.

Mitchell –
cin and cout are part of the std namespace, and they’re not functions. They’re almost like “pipes” in a sense. What you’re doing is essentially bit shifting (<> are bit shift operators) data into and out of them. As well, C++ still supports use of printf and scanf, so your std.cin and std.cout are by no means exclusive in their duties.

Don’t forget to check out :

Share.

About Author

Founder at Durofy. Blogs on technology & startups, runs a full service digital agency, teaches AP Calculus.

343 Comments

  1. Pingback: What to start with C / Python / Java or something else | dishantchavda

  2. Very good article. However, I would have to argue that C is not a low-level, but in fact a high-level programming language. High-level is close to what humans interpret, and low-level would be more or less machine language, such as assembly.

  3. Hey guyz..
    i’m a IT student n m now a dayz learning C language..
    i’ve learnt C++ first in high school.. Now, I feel C language is tougher than C++..
    this article helps me lil’.. But I need more difference in C n C++…
    can anyone show me the format of C?? How in C header files r written n how program is closed.. N is there void main in C??

    • C is easier (esp. after I learn about java, they’re twin! Without the pointer CMW). C++ much more complex with many feature addition.

  4. SHRINIVAS M.COM GULBARGA on

    hi ,friends this is shrinivas i have so much intresting inlearning linux and c++ i am studying in m.com 4 sem and especially animination is one of the my intresting topic

    =

    • High level or low level doesn’t related to functions. It depends on the level of abstrction, in c the level of abstraction is low as compare to cplus

  5. C++ is not a strict superset of C, ithere are some minor differences i.e. code that will compile in c but won’t compile in c++ such as void pointer casts. Function overloading is supported by C. 2 variables can point to the same memory location, ever heard of pointers? Talk of ‘level’ of languages is unjustified and there is no ‘mixed opinion’, there are high and low level languages i.e machine code/assembly (low) and 3rd generation onwards (high level). The word for “data hiding” you’re looking for is “encapsulation” and is part of the OOP paradigm and you already explained the paradigm difference, so it is a moot point. Please learn what you’re talking about before posting an article. .

  6. srinivasa rao chevala on

    C lamgauge is supporting the functional overloading. in a single program u r using no of printf and scanf functions, those are taking different values

  7. Hi friends,

    I am working as a trainer in networking and system administration and I am so much interested in learning Linux in deep, especially Linux Kernel. Can anyone tell which language Linux kernel is written? Someone is saying it is Assembly Level coding and some other are saying it is pure C programming language. If I have a good understanding of C Language, can I able to understand the Linux Kernel coding? (Of-course with the help of some Linux guru or by reading comments) ?

    Thanks a lot for this great site.

    Toms.

  8. According to Yashwant Kanetkar C is a middle level language but above according to the Point 3-C is low level language I think this is wrong not correct mostly we consider low level language is Machine language not C

  9. Heeey woww it was easy to understand coz it not only has the difference but
    also the meaning for it.. wowwwww realli useful info :) thank you soo much.. :)

  10. Pingback: Blue Ray Plus - Latest Technology News

  11. prathamesh :

    hey rishabh i m not able to handle the pointers and all the pointers stuff so can u tell me wer shuld i refer for the basics of pointers ????????

    & also tell me which book is best to refer for c& c++ programming w8ng for your reply …

    Hello! You can start with this post on the basics of pointers : http://www.durofy.com/programming/an-introduction-to-pointers-in-c-programming/
    Refer to a good programming book to learn the basics. I recommend “The C Programming Language” by Brian Kernighan & Dennis Ritchie to clear your basics. Once you are good in C, then move to C++.

  12. hey rishabh i m not able to handle the pointers and all the pointers stuff so can u tell me wer shuld i refer for the basics of pointers ????????

    & also tell me which book is best to refer for c& c++ programming w8ng for your reply …

  13. Limitation of C

    (1) Inability to express large program as an abstraction
    (2) Unsuited for very large scale programming
    (3) No Mechanism for information reuse with little modification [Team Contribution & Correction due to error is difficult]
    (4) Can only identify Errors & cannot handle Exceptions
    (5) C++ is Multi-paradigm language
    (6) Features like Data Hiding, Polymorphism, Inheritance are not available

  14. You can use multiple variables(pointers) to point into a single memory location in C. You use it especially when implementing linked lists.

  15. Hey Rishabh,
    I am new to C/C++ environment. Can you tell me the difference between the C/C++ IDEs/Compilers also what if I use C++ to compile code for C and vice versa? What difference will it make ?

  16. Mitchell :
    You can use functions inside of structs in C via pointers, but I supposed that’s not what you really mean, it just sounds slightly misleading to me.
    Also, cin and cout are part of the std namespace, and they’re not functions. They’re almost like “pipes” in a sense. What you’re doing is essentially bit shifting (<> are bit shift operators) data into and out of them. As well, C++ still supports use of printf and scanf, so your std.cin and std.cout are by no means exclusive in their duties.
    All in all a good article, just a couple nitpicks.

    You are not bit shifting. Bit shifting changes values it does not move variables.

    The operators are overloaded and called “insertion operators” in the iostream context. I’m not sure if you just wanted to seem smart or simply have a poor mental model but you are wrong and now everybody who read your addendum is also misinformed.
    http://www.cplusplus.com/reference/iostream/ostream/operator<</

  17. hiii can you please tell me the difference between while and for loop.why we use this both when they are peforming the same task and also where to use while and where to use for loop

  18. In 7., what does “functions insides structures” actually mean? I mean, I can use function pointers inside of structs perfectly fine. Do you mean functions that can access the structs data automatically?

    I also don’t get 10.
    When I do

    int a = 4;
    int *b = &a;

    isn’t this what you described as “using the same memory by different names”?

  19. Hehhh can yu please provide me the complete information with explanation on the main OOPS principles..please ya
    And the above information is perfct..thank yu ya..

  20. Thanx……boss.. this difference is very easy to store on my mind, its never forget to me.. short answers nice keep it up boss… and also keep this typ of answers always it will help full for students..like me

  21. shuhaibvalapuram on

    12.Main doesn’t Provide return 0 Automatically in c,but in c++ it is..
    13.No Boolean type in C,but it is present in c++
    14.We must declare functions before use in c++,but c does’t require it.
    15.presence of keyword ‘new’ instead malloc in c

  22. Alex D :

    Wait so can I learn C first and then move on to C++… will that work? Because I have started watching video tutorials about C and I am learning a lot but will I be able to do those things in C++?
    Please reply!
    Thanks

    That’s the only way it works. I hate to call C a “programming language”. It is more like a “programming prerequisite”. C is to programming what Algebra is to Calculus.

  23. Wait so can I learn C first and then move on to C++… will that work? Because I have started watching video tutorials about C and I am learning a lot but will I be able to do those things in C++?
    Please reply!
    Thanks

  24. You can use functions inside of structs in C via pointers, but I supposed that’s not what you really mean, it just sounds slightly misleading to me.

    Also, cin and cout are part of the std namespace, and they’re not functions. They’re almost like “pipes” in a sense. What you’re doing is essentially bit shifting (<> are bit shift operators) data into and out of them. As well, C++ still supports use of printf and scanf, so your std.cin and std.cout are by no means exclusive in their duties.

    All in all a good article, just a couple nitpicks.

  25. Pingback: Advantage of C over C++ ..!

  26. Nitin Sharma on

    My village is Himayoupur (G.B.Nagar). But at this time i am living in ghaziabad finally i will say notes are very helpful for self study and extra knowledge about everything.So for this facility i will thanks to internet service provider and notes provider.

  27. Just thought of another. Actually, this is a side-effect of not having classes, but dynamic allocation in C uses only malloc() and free(), since there is no concept of a constructor or destructor.

  28. Not a complete list. A couple of other differences:

    C allows void* to be assigned to another type with no warnings.
    C requires the struct keyword when defining a variable of a struct type. C++ automatically “typedefs” structs.
    C has no operator overloading.
    You can omit the return in main() in C.

    There are some others, but it’s been a while since I used C.

  29. Thanks a lot Sir!!!
    Its really a very basic thing in software empire.
    One can not point out such smaller but major differences.
    You gave us it as ready made.
    Thanks a lot once again!!!

    • @praveen – I agree there are always mixed opinions about this one. Some even like to call it a 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? Now, as we increase the abstraction and move away from the machine-level, the level of the language increases. So, the level is nothing but the level of abstraction. So, most of the languages we use in applications today will have aspects of both machine-level and user-level. The two levels are machine-level & user(real world)-level while high & low levels are relative terms. Although, C is on a lower level of abstraction “relatively”- when compared to C++. Hence, referred to here as low-level.

  30. Really Awesome … Thanks a lot boss u made my engineering worth …At last i came to know the basic difference between these two………………………thanks

  31. Pingback: Durofy » 10 Major Differences Between C And JAVA

  32. Pingback: techigg.com

  33. Pingback: C++ Tutorial

Leave A Reply