Difference Between C and C++: A Comprehensive Comparison Guide in 2023

difference between c and c++

Let’s discuss difference between c and c++ and relation between C and C++

Difference Between C and C++

CC++
Dennis Ritchie developed the programming language C at AT&T Bell Labs from 1969 to 1973.Bjarne Stroustrup, a brilliant mind, created C++ in 1979.
C lacks support for essential features such as polymorphism, encapsulation, and inheritance, making it unsuitable for object-oriented programming.The support for polymorphism, encapsulation, and inheritance in C++ is one of the key reasons why it is regarded as a powerful object-oriented programming language.
C is a subset of C++ programming language.C++ includes almost all the features of C, making it a superset of the language.
C programming language is exceptionally well-suited for supporting procedural programming in code development.C++ is a hybrid language, supporting both procedural and object oriented programming.
C separates data and functions due to being a procedural language.Objects in C++ offer a robust mechanism for bundling together data and functions, resulting in powerful encapsulation capabilities.
Information hiding is not supported by C.Encapsulation is a powerful technique that securely hides data within data structures and operators, ensuring they are used exactly as intended.

C supports built-in data types.
C++ supports both built-in and user-defined data types.
C is classified as a function-oriented language because it has the characteristics of a procedural programming language.C++ is an object-oriented language, as it follows the principles of object-oriented programming.
The file extension is “.c”.The file extension options include “.cpp”, “.c++”, “.cc”, or “.cxx”.

In C, inheritance is not supported.

Inheritance is supported by C++.
C uses scanf() and printf() functions for input and output operations. These functions are commonly used to read input from the user and display output to the screen. They provide a convenient way to interact with the user and display information.In C++, cin and cout are used for performing input and output operations.
Access modifiers are not present in C structures.Access modifiers are used in C++ structures to manage visibility and ensure data protection.
C does not provide direct support for exception handling.C++ supports exception handling.

Key Relation and Difference Between C and C++

  • In C++, you have the advantage of using classes to group together data and methods, while C lacks this feature.
  • Additionally, C++ supports inheritance, allowing one class to inherit the properties of another, a capability that C does not offer.
  • Polymorphism, another powerful feature of C++, enables objects of different types to be treated similarly, which is not possible in C.
  • Moreover, C++ is a compiled language, meaning that the code is converted into machine code before execution, whereas C is interpreted line by line.
  • C++ is a powerful programming language that integrates object-oriented programming (OOP), while C follows a procedural approach.
  • C++ has automatic memory management with constructors and destructors, whereas C relies on manual memory management. The C++ Standard Library offers a wide range of container classes, surpassing C in this aspect. C++ has stricter type checking and provides extensive support for exception handling, unlike C.
  • C++ allows the usage of templates for code reuse, which is not possible in C. The C++ Standard Library has I/O stream classes for seamless input and output handling, while the C Standard Library uses a basic file-based I/O approach.
  • Although C may have faster performance, the versatility and power of C++ outweigh this advantage.
  • C code can be used in C++ programs, but not the other way round, as C++ introduces additional features and syntax that C does not have.
  • C++ is superset of C.
  • As C++ adds keyword that are not reserved in C, these added keywords can be used as identifiers in C. (but no C++ compiler can compile such C program).
  • C programmers can omit function prototypes.
  • The memory allocation operators new and delete of C++ replace standard C’s malloc (memory allocation) and free function.
  • The standard C++ string class replaces the character array processing functions declared in the standard C library’s <cstring> header file.
  • The C++ iostream class library replaces standard C’s stdio function library for console input and output.
  • C++ try/catch/throw exception handling mechanism replaces standard C’s setjmp() and longjmp() functions.
  • C++ is a better version of C.
  • C++ is a general purpose language.
  • C++ supports object oriented programming (OOP).
  • C++ supports generic programming, where we can use data type as argument.
  • C++ is bias towards system programming.
  • C++ supports data abstraction.
  • C++ supports both types of overloading i.e. method overloading and operator overloading.
  • C++ allows pointer arithmetic.
  • The access controls available in C++ are public, protected, private and friend.
  • C++ is a statically types language that requires all variables declared with a specific type.

History of C

  • Ken Thompson developed Language B in 1970 at Bell Labs.
  • In 1971, Dennis Ritchie expanded on B by introducing character types and rewrote the compiler to generate PDP-11 machine instructions.
  • This enhanced version of B was called ‘new B’ or ‘NB’.
  • When the PDP-11 computer arrived at Bell Labs, Ritchie created a new language based on B, which he named C.
  •  By early 1973, the foundation of modern C was laid.
  • During the 1980s, the popularity of the C language grew significantly. Compilers became widely accessible for different machine architectures and operating systems.

History of C++

  • The earlier version of C++ language, known as “C with classes” have been in use since 1980.
  • The first use of C++ outside a research organization started in July 1983.
  • Rick Mascitti coined the term C++ in the summer of 1983 as an extension of C.
  • BCPL (Basic Combined Programming Language) // comment conversion is reintroduced in C++
  • Other main source of inspiration for C++ was Simula67.
  • The class concept in C++ was borrowed from Simula67.
  • The facility of overloading operators and the freedom to place a declaration wherever a statement can occur of C++ resembles Algol68.
  • The exception handling mechanism of C++ was inspired partly by Ada and ML.
  • Other developments during 1985-1995 (multiple inheritance, pure virtual functions and namespaces) were driven by experience with the use of C++
  • Some of the important milestones on the road of Object Orientation are
  • 1968 – Simula67 – The first object oriented language.
  • 1970 – Graphical User Interface (GUI) developed using Object Orientation.
  • 1972 – David Parma’s seminar paper on “Information hiding”
  • 1980 – First version of Smalltalk(Alan Kay)
  • 1983 – First version of C++
  • 1988 – First version of Eiffel (Bertrand Meyer)
  • C++ is influenced by ALGO68, C,ML and Simula.
  • Languages that are influenced by C++ are Ada95, C#, Java,Perl, Python and PHP etc.
  • In the journey of C++, standardized (by ISO) versions are –
    C++ 98 released in 1998
    C++03 released in 2003
    C++11 released in 2011
    C++14 released in 2014
    C++17 released in 2017

Difference between C++ with other OOP languages

Eiffel by Bertrand Meyer in 1985. SmallTalk by Alan Kay, Dan Ingalls, Adele Goldberg in 1972.

FeatureEiffel (1985)Smalltalk(1972)C++ (1983)C# (2000)Java (1995)
Object – OrientationPurePureHybrid/Multi-ParadigmHybridHybrid
Static / Dynamic TypingStaticDynamicStaticStaticStatic
Generic ClassesYesNot ApplicableYesNoNo
InheritanceMultipleSingleMultipleSingle Class,multiple interfacesSingle class, multiple interfaces
Feature RenamingYesNoNoNoNo
Method OverloadingNoNoYesYesYes
Operator OverloadingYesYesYesYesNo
Higher Order FunctionsAgents (with version 5)BlocksNoNoNo
Lexical ClosuresYes(Inline agents)Yes(blocks)NoNoNo
Garbage CollectionMark and Sweep or GenerationalMark and Sweep or GenerationalNoneMark and Sweep or GenerationalMark and Sweep or Generational
Uniform AccessYesNot ApplicableNoNoNo
Class Variables/MethodsNoYesYesYesYes
ReflectionYes (version 5)YesNoYesYes
Access ControlSelective ExportProtected Data, Public Methodspublic, protected,privatepublic, protected,privatepublic, protected,private
Design by ContractYesNoNoNoNo
MultithreadingImplementation DependentImplementation DependentLibrariesYesYes
Regular ExpressionsNoNoNoStandard LibraryStandard Library
Pointer ArithmeticNoNoYesYesNo
Language IntegrationC,C++,JavaCC,AssemblerAll .NET LanguagesC, some C++
Built in SecurityNoNoNoYesYes

Leave a Reply

Your email address will not be published. Required fields are marked *