Difference Between C and C++
Overview
C and C++ are programming languages that are used to create applications. They are two of the most widely used and oldest programming languages. This article will explain the difference between C and C++ programming languages. C++ is a superset of C since it was inspired by and derived from C.
Scope of article
This article would enhance our knowledge of two of the most common programming languages: C and C++. And we will discuss, where are these languages used.
Some topics we would go through in this article are:
- What are C and C++ languages
- The difference between the C and C++ languages
- Which language would be best to start with for a beginner
C and C++ are two of the oldest programming languages still in use. Though C++ is a direct descendant of the C language, it has higher efficiency and performance. Each programming language comes with its own set of advantages and disadvantages.
C++ programming language is an upgraded version of the C programming language with the inclusion of object-oriented functionality.
Difference Between C and C++
Some of the common differences between C and C++ are :
- The classes and objects are not supported in the procedural programming language such as the C language but are supported by C++.
- Language such as C++ is procedural as well as object-oriented programming oriented and hence is called a combination of these two programming language techniques.
- Many features of object-oriented programming language which are present in C++ such as Abstraction, Inheritance, Encapsulation, and Polymorphism are also not available in C language.
- C++ also supports some more primitive data types such as boolean and string which were not supported in C language.
Before we go into the details, let’s take a glance at what both languages are and what defines them :
What is C Programming Language?
The C programming language is a general-purpose and high-level language that facilitates structured programming. C was later on chosen as a system development language because it generates code that executes almost as quickly as an assembly language code.
The C programming language was created by Dennis Ritchie at Bell Labs in 1972 to allow utilities to run on Unix systems. Because C programs are fast, they allow programmers to manually control computer hardware.
The strength of the C programming language is its performance and its use for coding on a wide range of platforms. Operating systems, interpreters, compilers, and microcontrollers are some of the systems that use the C language for their internal programming.
What is C++ Programming Language?
C++ was created by Bjarne Stroustrup and was considered the finest version of C when it first appeared in 1985. In 1979, while working at Bell Labs, Bjarne started developing the C++ programming language. He aimed to build a C extension that was more efficient and versatile than the C programming language.
Object-oriented programming (OOPS) is made possible using C++. OOPS is a concept in programming in which we write programs based on the principle of real-world objects. Like every object in the world has its own set of characteristics and functions to perform, similarly, object-oriented programming helps us to implement this approach through programming.
OOPS has four basic principles as given below:
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
C++ has a low abstraction level and relies on manual memory management. It is lightweight as compared to C programming language and can be used to create apps for a number of different platforms.
C vs C++
Let's summarise Difference Between C and C++:
Parameters | C | C++ |
---|---|---|
Programming Paradigm | Procedural language | C++ is both a procedural and object-oriented programming language (OOPS) |
Developer | Dennis Ritchie | Bjarne Stroustrup |
Origin | It is based on Assembly Language | It is based on C language |
Abstraction, Encapsulation, Inheritance, Polymorphism | C does not support the given OOPS principles. | C++ supports all of the given principles. |
Operator Overloading | Not supported | Supported |
Keywords | C has 32 keywords. | C++ has 63 keywords |
Constructor/Destructor | No constructor or destructor is supported in C | Both constructors and destructors are supported |
Exception Handling | Not supported | Supported |
Approach | C uses top-down approach | C++ uses bottom-up approach |
Storage and dynamic memory allocation | C uses functions- malloc and calloc for storage and dynamic memory allocation | C++ uses operators- new and delete for performing storage and dynamic memory allocation |
Header files | Uses header file eg. stdio.h | Uses header file eg. iostream.h |
Standard I/O operations | Uses printf and scanf for input and output operations | C++ uses cin>> and cout<< and also printf and scanf |
Templates | Does not supports templates | Supports templates |
File extension | File extension for a C program is .c | File extension for C++ program is .cpp |
Program division | The program is divided into small codes known as functions | A C++ program is divided into small pieces of code known as classes and objects. |
Inline function | C does not supports inline functions | C++ supports inline functions |
Conclusion
-
We saw difference Between C and C++ Languages.
-
C++ is an extension of the C programming language that is more efficient and versatile.
-
C++ has a low abstraction level and relies on manual memory management. It is lightweight as compared to C programming language and can be used to create apps for a number of different platforms.
-
We’ve seen that C is a procedural language and C++ is an object-oriented programming language and many features are unique only to C++.
-
Because C++ is developed from C, it provides many of the features same as C and some which are better than C.