Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Difference between C and C++
Both C and C++ are middle-level programming languages that are used for developing system software as well as application software. C is a procedural programming language which have low-level memory access and minimal runtime; therefore, it is used for writing operating systems, embedded systems, and system-level programs.
whereas C++ is just an extension of the C language, which is both a procedural programming language and object-oriented. Therefore, having extra features that make it suitable for game development, GUI applications, and high-performance software.
C Programming Language
C is a general-purpose, procedural programming language, which was developed by Dennis M. Ritchie at AT&T Bell Labs in 1972. At first, it was designed to develop the UNIX operating system and implemented on the DEC PDP-11 computer.
In 1978, Brian Kernighan and Dennis Ritchie published the first ever documentation of the C language, which is now known as the K&R standard (named after Kernighan and Ritchie). The UNIX operating system, C compiler, and all UNIX application programs have been written in C. In fact, it is known as the "mother of all programming languages" because many other languages like C++, Java, and Python are based on its core principles. It has now become a widely used professional language for various reasons −
- Easy to learn
- Structured Programming
- Speed and Performance
- Rich Library and Built-in Functions
- Handles low-level activities, meaning it can directly interact with hardware through pointers and memory manipulation
C Example
Here is the following basic C code example −
#include <stdio.h>
int main() {
/* Print message to the console */
printf("Hello, World!\n");
return 0;
}
Hello, World!
- Here #include <stdio.h> tells the compiler to include the standard library "stdio.h" (Standard Input/Output header). This library contains useful functions like printf().
- int main() is the main function, from where the C program starts, where int means the function will return an integer value.
- printf() prints the written text on the screen and '\n' adds a new line, making the cursor move to the next line after printing.
- return 0; this line ends the program, sending 0 back to the system, where 0 indicates that the program ran successfully.
C++ Programming Language
C++ is a general-purpose, object-oriented programming language developed by Bjarne Stroustrup in 1980 at AT&T Bell Labs in Murray Hill, New Jersey, as an extension of the C language. It was initially named 'C with Classes' but was later renamed C++ in 1983.
C++ is a superset of C, as it's a combination of C with object-oriented features, which includes extra concepts like classes, objects, inheritance, polymorphism, etc. All C code can run in C++, but not all C++ code can run in C. C++ is considered a middle-level language as it includes the features of both high-level and low-level programming languages. In this, the type checking is performed during compile-time rather than run-time, therefore, it's also considered a statically typed language.
Comparison Table
Here is the following comparison table showcasing the differences between C and C++ −
| Sr.No. | Key | C | C++ |
|---|---|---|---|
| 1 | Developer | Dennis Ritchie (1972) | Bjarne Stroustrup (1980) |
| 2 | OOPS | Does not support OOPS concepts | Supports OOPS concepts like polymorphism, encapsulation, and inheritance |
| 3 | Set Relationship | C is a subset of C++ | C++ is a superset of C |
| 4 | Keywords | C has 32 keywords | C++ has 95+ keywords |
| 5 | Paradigm | Procedural Programming Language | Supports both procedural and object-oriented programming |
| 6 | Standard Libraries | C Standard Library (stdio.h, math.h, etc.) | C++ Standard Template Library (STL) |
| 7 | Programming Approach | Top-Down Approach | Bottom-Up Approach |
| 8 | Data and Function | Data and Functions are separate | Data and Functions are encapsulated together as an object |
| 9 | Information Hiding | Not supported | Supported via encapsulation |
| 10 | Overloading | Function and Operator overloading are not supported | Function and Operator overloading are supported |
| 11 | Language Nature | Function-driven language | Object-driven language |
| 12 | Structure | C structure does not support defining functions | C++ structure supports defining functions |
| 13 | Memory Management | Manual (malloc/free) | Dynamic with Constructors/Destructors, new/delete |
| 14 | Reference Variables | Not supported | Supported |
| 15 | Virtual and Friend Functions | Not supported | Supported |
| 16 | Exception Handling | Not supported | Supported |
Conclusion
C is ideal for system programming and embedded systems due to its simplicity and efficiency, while C++ extends C with object-oriented features, making it suitable for complex applications and software development. Both languages remain fundamental to modern programming, with C focusing on procedural programming and C++ offering both procedural and object-oriented approaches.
