The Wayback Machine - https://web.archive.org/web/20240612122740/https://www.geeksforgeeks.org/difference-between-c-and-c/
Open In App

Difference between C and C++

Last Updated : 07 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Similarities between C and C++ are: 

  • Both the languages have a similar syntax.
  • Code structure of both the languages are same.
  • The compilation of both the languages is similar.
  • They share the same basic syntax. Nearly all of C’s operators and keywords are also present in C++ and do the same thing.
  • C++ has a slightly extended grammar than C, but the basic grammar is the same.
  • Basic memory model of both is very close to the hardware.
  • Same notions of stack, heap, file-scope and static variables are present in both the languages.

Differences between C and C++ are: 
C++ is often viewed as a superset of C. C++ is also known as a “C with class” This was very nearly true when C++ was originally created, but the two languages have evolved over time with C picking up a number of features that either weren’t found in the contemporary version of C++ or still haven’t made it into any version of C++. That said, C++ is still mostly a superset of C adding Object-Oriented Programming, Exception Handling, Templating, and a more extensive standard library. 

Below is a table of some of the more obvious and general differences between C and C++. There are many more subtle differences between the languages and between versions of the languages.

C C++
C was developed by Dennis Ritchie between the year 1969 and 1973 at AT&T Bell Labs. C++ was developed by Bjarne Stroustrup in 1979.
C does no support polymorphism, encapsulation, and inheritance which means that C does not support object oriented programming. C++ supports polymorphism, encapsulation, and inheritance because it is an object oriented programming language.
C is (mostly) a subset of C++. C++ is (mostly) a superset of C.
Number of keywords in C:
* C90: 32
* C99: 37
* C11: 44
* C23: 59
Number of keywords in C++:
* C++98: 63
* C++11: 73
* C++17: 73
* C++20: 81
For the development of code, C supports procedural programming. C++ is known as hybrid language because C++ supports both procedural and object oriented programming paradigms.
Data and functions are separated in C because it is a procedural programming language. Data and functions are encapsulated together in form of an object in C++.
C does not support information hiding. Data is hidden by the Encapsulation to ensure that data structures and operators are used as intended.
Built-in data types is supported in C. Built-in & user-defined data types is supported in C++.
C is a function driven language because C is a procedural programming language. C++ is an object driven language because it is an object oriented programming.
Function and operator overloading is not supported in C. Function and operator overloading is supported by C++.
C is a function-driven language. C++ is an object-driven language
Functions in C are not defined inside structures. Functions can be used inside a structure in C++.
Namespace features are not present inside the C. Namespace is used by C++, which avoid name collisions.
Standard IO header is stdio.h. Standard IO header is iostream.h.
Reference variables are not supported by C. Reference variables are supported by C++.
Virtual and friend functions are not supported by C. Virtual and friend functions are supported by C++.
C does not support inheritance. C++ supports inheritance.
Instead of focusing on data, C focuses on method or process. C++ focuses on data instead of focusing on method or procedure.
C provides malloc() and calloc() functions for dynamic memory allocation, and free() for memory de-allocation. C++ provides new operator for memory allocation and delete operator for memory de-allocation.
Direct support for exception handling is not supported by C. Exception handling is supported by C++.
scanf() and printf() functions are used for input/output in C. cin and cout are used for input/output in C++.
C structures don’t have access modifiers. C ++ structures have access modifiers.
There is no strict type checking in C programming language. Strict type checking in done in C++.  So many programs that run well in C compiler will result in many warnings and errors under C++ compiler.
C does not support overloading C++ does support overloading
Type punning with unions is allows (C99 and later) Type punning with unions is undefined behavior (except in very specific circumstances)
Named initializers may appear out of order Named initializers must match the data layout of the struct
File extension is “.c” File extension is “.cpp” or “.c++” or “.cc” or “.cxx”
Meta-programming: macros + _Generic() Meta-programming: templates (macros are still supported but discouraged)
There are 32 keywords in the C There are 97 keywords in the C++


Previous Article
Next Article

Similar Reads

Difference between Difference Engine and Analytical Engine
Introduction: The development of computing technology has a rich history, with many inventions and innovations leading to the creation of the modern computer. Two such machines, the Difference Engine and Analytical Engine, were created by the English mathematician and inventor Charles Babbage in the 19th century. While these machines share some sim
7 min read
Difference between Voltage Drop and Potential Difference
Voltage Drop is defined as the decrease in the electric potential along the path of current that is flowing in an electric circuit. Voltage drop can be assigned at each point in the electric circuit that is proportional to the electrical elevation. The amount of energy delivered per second to any component in the circuit is equal to the voltage dro
4 min read
Difference Between Electric Potential and Potential Difference
The flow of electric charges is known as electricity, and it is responsible for producing electric current. An important word associated with electricity is electric potential. A potential difference is required to create the flow of electrons and hence, produce electricity. Before understanding the difference between electric potential and potenti
7 min read
Difference and Similarities between PHP and C
PHP is a server-side scripting language designed specifically for web development. It can be easily embedded in HTML files and HTML codes can also be written in a PHP file. The thing that differentiates PHP from a client-side language like HTML is, PHP codes are executed on the server whereas HTML codes are directly rendered on the browser. C is a
3 min read
Difference between Stop and Wait protocol and Sliding Window protocol
Introduction: Both Stop and Wait protocol and Sliding Window protocol are the techniques to the solution of flow control handling. The main difference between Stop-and-wait protocol and Sliding window protocol is that in Stop-and-Wait Protocol, the sender sends one frame and wait for acknowledgement from the receiver whereas in sliding window proto
4 min read
Similarities and Difference between Java and C++
Nowadays Java and C++ programming languages are vastly used in competitive coding. Due to some awesome features, these two programming languages are widely used in industries as well as comepetitive programming . C++ is a widely popular language among coders for its efficiency, high speed, and dynamic memory utilization. Java is widely used in the
6 min read
Difference between Time Tracking and Time and Attendance Software
Time tracking and time and attendance software are tools that help businesses track the time that employees spend on tasks and their attendance records. These tools can help businesses automate their time tracking processes, reduce errors and inaccuracies, and ensure that employees are paid accurately for the time they work. Time tracking software
4 min read
Difference Between Single and Double Quotes in Shell Script and Linux
Single quotes and double quotes are both functional in Linux while working with shell scripts or executing commands directly in the terminal but there is a difference between the way the bash shell interprets them. Single quotes: Enclosing characters in single quotation marks (') holds onto the literal value of each character within the quotes. In
3 min read
Difference Between Store‑and‑Forward Switching and Cut‑Through Switching
Switching is a technique that is used to transmit data between the networks. It is achieved by using switches that are used to connect multiple LAN networks. Switches forward the data packets based on their MAC addresses. Switching is used to efficiently utilize the bandwidth of the network and reduce the collisions between the packets. Switching t
5 min read
Difference Between Monophyletic and vs Paraphyletic and vs Polyphyletic
In phylogeny, a taxon is a collection of organisms. Defining taxa makes it simpler to classify and identify creatures while also helping us to understand how they relate to one another. Based on these traits, taxa are developed. While some taxa are made up of unrelated creatures, others contain related species. Taxa classify descendants and ancesto
7 min read
Practice Tags :