C++ Introduction | C vs C++
This is an introductory article for C++ and Object Oriented Programming Concepts. We will also learn uses of C++ and difference between C and C++.
Basics of C++
C++ is a general-purpose, case-sensitive language that follows Object Oriented Programming (OOP) Concept and it was developed at AT & T Bell laboratories in the early 1979s by Bjarne Stroustrup. The initial name of C++ was C with Classes but later on it was renamed as C++.
C++ is a middle-level language because it supports both high-level language and low-level language features. C++ is an extension to C language or superset of C Language and supports Classes, Inheritance, function overloading and operator overloading which C language was lacking.
Object-Oriented Programming Concepts
The Object-Oriented Programming (OOP) languages like C++ and Java follow a different programming principles from structured programming languages like C and COBOL. Here are some of them
- Class: A class represents a set of objects that share common characteristics and behavior. Example of class can be considered as Fruit, car etc.
- Object: An Object is an entity with specific characteristics and specific behavior. An object may have a name, a set of attributes, and a set of actions or services. Example of object can be considered as Apple, Mango, Grapes, Banana etc in class Fruits and Mercedes, BMW, Audi etc in class car.
- Data Abstraction: Abstraction is the act of representing essential features without including the background details.
- Data Encapsulation: Encapsulation is the act of combining data and functions into single unit (class).
- Inheritance: inheritance is the capability of one class to inherit all the properties from another class. Important advantage of Inheritance is the code reusability.
- Polymorphism: Polymorphism is composed of two words ’poly’ means many and ’morph’ means forms. So we can say that polymorphism means ’many forms’.
Uses Of C++
With the help of C++ programming language, we can develop different type of applications such as:-
- Windows Applications
- Client-Server Application
- Device Drivers
- Embedded System
C vs C++
Now lets see some of the difference between C and C++.
|C++ is an Object-Oriented Programming.||C is a structured, procedural and case sensitive programming language.|
C++ variables can be
declared anywhere in the program where we require it.
|The variables declaration must be declared before any executable statement.|
|C++ supports Operator Overloading.||C does not support Operator Overloading.|
|In C++, Encapsulation hides the data to ensure that data structures and operators are used as intended.||In C, data are free entities and can be manipulated by outside code. This is because C does not support information hiding.|
|C++ supports Function Overloading.||C does not support function overloading.|
|In C++, we use cout() functions for output and cin() function for input from user.||In C, we use printf() function for output and scanf() function for input from user.|
|C++ follows bottom-up approach.||C follows top-down approach.|
|We can declare a function within a structure in C++.||C uses structure, but we can’t declare any function in structure.|
|C++ uses concept of object, we can call any function through object.||There is no concept of object, here we call a function using function name.|
|Exception Handling in C++ is easy because C++ provide try-catch block for Exception Handling.||C has no proper function for Exception Handling. Exception handling is difficult through structure and function.|
We have included only basic differences which new developers can easily understand. This list can grow even more if we dig deep into both the languages. Please drop a comment, if you want us to include more differences in the list.
You can also read our article on differences between Java and C/C++.
That's all for this topic. If you guys have any suggestions or queries, feel free to drop a comment. We would be happy to add that in our post. You can also contribute your articles by creating contributor account here.
Happy Learning 🙂
If you like the content on CodePumpkin and if you wish to do something for the community and the planet Earth, you can donate to our campaign for planting more trees at CodePumpkin Cauvery Calling Campaign.
We may not get time to plant a tree, but we can definitely donate ₹42 per Tree.
About the Author
Comments and QueriesIf you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code class="java"> String foo = "bar"; </code></pre>For more information on supported HTML tags in disqus comment, click here.