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;
}
  • 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.

C++ Example

Here is the following basic C++ code example.

#include <iostream>
int main() {
    std::cout << "Hello World!" << std::endl;
    return 0;
}
  • #include <iostream> tells the compiler to include the input/output library, which allows you to use std::cin (taking input from the user) and std::cout (printing out the result).
  • int main() is the main function, from where the C++ program starts. Here, the int indicates the return value will be an integer value.
  • std::cout is the console output, which prints the written messages.
  • endl stands for "end line", causing the cursor to move to the next line after printing.
  • A return 0; indicates the program has been successfully executed without any error.

Comparison Table

Here is the following comparison table showcasing the differences between C and C++.

Sr.No. Key C C++
1 Developer Dennis Richie (1969-1973)  Bjarne Stroustrup (1979) 
2 OOPS Does not support OOPS concepts. Supports OOPS concepts like polymorphism, encapsulation, and inheritance.
3 Set C is a subset of C++ C++ is a superset of C
4 keywords C has 32 keywords. C++ has 52 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 Function Function-driven language. Object-driven language.
12 Structure C structure does not support defining functions. C++ Structure supports defining a function.
13 Memory Management Manual 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

Updated on: 2025-04-14T11:35:43+05:30

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements