Anda di halaman 1dari 42

cs-Fundamentals.

com
Programming Tutorials and Interview Questions
Home
C Programming
Java Programming
Data Structures
Web Development
Tech Interview

What is the difference between C and C++?


Gain new skills in
10,000 hours data, cloud,
security, mobile &
made easy more—start a trial
pluralsight.com

The major difference between C and C++ is that C is a procedural programming language and
does not support classes and objects, while C++ is a combination of both procedural and object
oriented programming language; therefore C++ can be called a hybrid language. The following
table presents differences between C and C++ in detail.

Difference between C and C++


C C++

C was developed by Dennis Ritchie between C++ was developed by Bjarne Stroustrup in
1969 and 1973 at AT&T Bell Labs. 1979 with C++'s predecessor "C with Classes".

When compared to C++, C is a subset of C++. C++ is a superset of C. C++ can run most of C
code while C cannot run C++ code.

C supports procedural programming C++ supports both procedural and object


paradigm for code development. oriented programming paradigms; therefore
C++ is also called a hybrid language.

C does not support object oriented Being an object oriented programming


programming; therefore it has no support for language C++ supports polymorphism,
polymorphism, encapsulation, and encapsulation, and inheritance.
inheritance.

In C (because it is a procedural programming In C++ (when it is used as object oriented


language), data and functions are separate programming language), data and functions
and free entities. are encapsulated together in form of an
object. For creating objects class provides a
blueprint of structure of the object.

In C, data are free entities and can be In C++, Encapsulation hides the data to
manipulated by outside code. This is because ensure that data structures and operators are
C does not support information hiding. used as intended.

C, being a procedural programming, it is a While, C++, being an object oriented


function driven language. programming, it is an object driven language.

C does not support function and operator C++ supports both function and operator
overloading. overloading.

C does not allow functions to be defined In C++, functions can be used inside a
inside structures. structure.

C does not have namespace feature. C++ uses NAMESPACE which avoid name
collisions.

A namespace is a declarative region that


provides a scope to the identifiers (the names
of types, functions, variables, etc) inside it.
Namespaces are used to organize code into
logical groups and to prevent name collisions
that can occur especially when your code
base includes multiple libraries. All
identifiers at namespace scope are visible to
one another without qualification. Identifiers
outside the namespace can access the
members by using the fully qualified name
for each identifier.

C uses functions for input/output. For C++ uses objects for input output. For
example scanf and printf . example cin and cout .

C does not support reference variables. C++ supports reference variables.

C has no support for virtual and friend C++ supports virtual and friend functions.
functions.
C provides malloc() and calloc() functions C++ provides new operator for memory
for dynamic memory allocation, and free() allocation and delete operator for memory
for memory de-allocation. de-allocation.

C does not provide direct support for error C++ provides support for exception handling.
handling (also called exception handling) Exceptions are used for "hard" errors that
make the code incorrect.

Hope you have enjoyed reading differences between C and C++. This comparison of C and C++
explains feature-wise difference between both programming languages. Please do write us if
you have any suggestion/comment or come across any error on this page. Thanks for reading!

References
1. Kernighan and Ritchie, The C Programming Language, 2nd Ed.
2. C: The Complete Reference
3. Randal E. Bryant, David R. O'Hallaron, Computer Systems: A Programmer's Perspective.

48 Comments Sort by Top

Add a comment...

Adarsh Kumar Software engineer at AK Aerotek Software Center Pvt Ltd


good job sir
Like · Reply · Mark as spam · 8 · May 25, 2016 9:18pm

Choubey Rashi Studying at College students


please give detail on some points .....
why reference variable is not support in c
Like · Reply · Mark as spam · 6 · Aug 20, 2016 3:52am

Charanjiť Singh CEO/Founder/Owner at C.S PC Doctors Hoshiarpur


Because idea of Referencing didn't came in Denis Ritchie's mind.
Like · Reply · Mark as spam · 17 · Dec 21, 2017 8:54pm · Edited

Abhishek Sagar Software Engineer 3 at Juniper Networks India Pvt. Ltd.


arent pointers are reference variables ??
Like · Reply · Mark as spam · Jul 19, 2017 10:58pm

Charanjiť Singh CEO/Founder/Owner at C.S PC Doctors Hoshiarpur


No
Like · Reply · Mark as spam · Jul 20, 2017 1:46am

Show 1 more reply in this thread

Sai Prakash L Oxford College of Engineering


tq sir
Like · Reply · Mark as spam · 1 · Aug 20, 2016 8:27am

Sukesh Pal GLA University


helpfull,...
Like · Reply · Mark as spam · 1 · Sep 4, 2016 5:49am

Vishnu Thorat MIT College of Engineering Aurangabad


nice one it really help us...
Like · Reply · Mark as spam · 2 · Sep 10, 2016 11:24pm

Munnaf M Abdul Doctoral Research Fellow in Precision Soil & Crop Engineering (SiTeMan) at Gent
University
As a beginer, What should I follow C or C++?
Like · Reply · Mark as spam · 1 · Sep 14, 2016 10:19am

Sunil Pathania Chandigarh University


c then c++
Like · Reply · Mark as spam · Feb 3, 2017 9:24pm

Omar Masri
i would request C++ its much easier and more used , i'm a begginer too and im learning C++
Like · Reply · Mark as spam · Apr 26, 2017 3:57pm

Teboho Sefuthi Vancouver, British Columbia


Omar Masri what resources are you using to learn C++?
Like · Reply · Mark as spam · May 1, 2017 8:09pm

Show 1 more reply in this thread

Flavious Correia VIVA Institute of MCA


Flavious Correia VIVA Institute of MCA
Sir,u hav not mentioned difference between manipulaters in c/c++
Like · Reply · Mark as spam · Sep 16, 2016 11:14pm

Srinath Raja Engineer at None


v v good
Like · Reply · Mark as spam · Sep 24, 2016 6:47am

Saleh Khan Secretary at Ministry of Education (Afghanistan)


it was not the important information please apload the videos of this lesons
Like · Reply · Mark as spam · Oct 1, 2016 3:00am

Sibi Sri Sai Ram Engg College


Also in C++ you can initiate the variable used in the loop which cannot be done in C;
Eg for(int i=0;i<n;i++) {}
Like · Reply · Mark as spam · 2 · Oct 6, 2016 6:20am

Nandhu Krish Engineer at Student


we can use bro...once check!!!
Like · Reply · Mark as spam · 1 · Jun 5, 2017 10:31pm

Ope Wiji
bruh, both C and C++ have versions.. for example ANSI C, ISO C, C99, C11, and C++98, C++11,
C++14, etc..

starting C99 version what you're asking is supported and syntax for(int i=0;i<n;i++) {} will be
compiled ok
Like · Reply · Mark as spam · 1 · Oct 19, 2017 7:31am · Edited

Load 10 more comments

Facebook Comments Plugin


Get Free Tutorials by Email

Email:

Subscribe

85 26 72

About the Author


Krishan Kumar is the main author for cs-fundamentals.com. He is a software
professional (post graduated from BITS-Pilani) and loves writing technical
articles on programming and data structures.

Today's Tech News


Huawei's AI phone tested by driving car at dog
Posted on Thursday March 01, 2018

A smartphone that recognises objects is tested by using it to try to stop a car running over a
dog.

Bill Gates says crypto-currencies cause deaths


Posted on Thursday March 01, 2018

In a Reddit thread, the Microsoft founder expresses his concerns about digital currencies like
Bitcoin.

AI finds novel way to beat classic Q*bert Atari video game


Posted on Thursday March 01, 2018

The AI code found quirks in the Atari game code that let it score a lot of points, researchers
found.

Courtesy BBC News


    

Home Contact Us About Us Write For Us RSS Feed

© copyright 2016 cs-Fundamentals.com

Anda mungkin juga menyukai