Lesson 4 of 60 – C++ vs C
7%

C++ vs C

C and C++ are closely related programming languages. C++ evolved from C and retains many concepts and syntax from C, while adding features such as classes, objects, inheritance, polymorphism, templates, and a larger standard library.

Note: C and C++ are separate programming languages. Although much of their syntax is similar, they have different language standards and features.

1. Basic Difference

C is primarily a procedural programming language, while C++ supports procedural programming as well as object-oriented and generic programming.

C  → Procedural Programming

C++ → Procedural + Object-Oriented + Generic Programming

2. Origin

C was developed before C++. C++ was developed as an extension of the C programming language.

The early version of C++ was known as C with Classes.

3. Programming Paradigm

C mainly follows a procedural programming approach. Programs are organized around functions and procedures.

C++ supports multiple programming approaches, including:

  • Procedural programming
  • Object-oriented programming
  • Generic programming

4. Classes

C does not provide classes as a built-in language feature. C++ provides classes for creating user-defined types.

class Student {
public:
    int age;
};

5. Objects

C++ allows programmers to create objects from classes.

class Student {
public:
    int age;
};

int main() {

    Student s1;

    s1.age = 20;

    return 0;
}

The object s1 is an instance of the Student class.

6. Object-Oriented Programming

C++ provides built-in language features for object-oriented programming. Important concepts include:

  • Classes
  • Objects
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction

C does not provide these concepts as built-in object-oriented language features.

7. Encapsulation

C++ supports encapsulation through classes and access specifiers such as private, protected, and public.

class Account {

private:
    double balance;

public:
    void setBalance(double amount) {
        balance = amount;
    }
};

8. Inheritance

C++ supports inheritance, which allows one class to derive from another class.

class Animal {
};

class Dog : public Animal {
};

Inheritance is a built-in C++ class feature.

9. Polymorphism

C++ supports polymorphism through features such as function overloading and virtual functions.

void display(int x) {
}

void display(double x) {
}

This is an example of function overloading in C++.

10. Function Overloading

C++ allows multiple functions with the same name when their parameter lists are different.

void add(int a, int b) {
}

void add(double a, double b) {
}

Function overloading is supported by C++ but is not a feature of C.

11. Operator Overloading

C++ supports operator overloading for user-defined types. This allows operators to be given appropriate behavior for class objects.

For example, a class can define how the + operator works with its objects.

12. Templates

C++ supports templates for generic programming. Templates allow functions and classes to work with different data types.

template <typename T>
T maximum(T a, T b) {
    return (a > b) ? a : b;
}

Templates are an important feature of C++.

13. Standard Input and Output

C commonly uses functions such as printf() and scanf() for standard input and output.

C++ commonly uses stream objects such as std::cout and std::cin.

// C++
#include <iostream>

std::cout << "Hello";
std::cin >> value;

14. Header Files

Both C and C++ use header files, but their standard libraries provide different headers and facilities.

C example:

#include <stdio.h>

C++ example:

#include <iostream>

15. Input and Output Example in C

#include <stdio.h>

int main() {

    int age;

    printf("Enter age: ");
    scanf("%d", &age);

    printf("Age = %d", age);

    return 0;
}

16. Input and Output Example in C++

#include <iostream>

int main() {

    int age;

    std::cout << "Enter age: ";
    std::cin >> age;

    std::cout << "Age = " << age;

    return 0;
}

17. Memory Management

Both languages provide low-level memory management capabilities. C commonly uses malloc(), calloc(), realloc(), and free().

C++ provides new and delete, along with modern smart pointers such as std::unique_ptr and std::shared_ptr.

18. Structures

Both C and C++ support structures, but their language rules differ. C++ structures can contain member functions and support features associated with classes.

struct Student {

    int age;

    void show() {
        std::cout << age;
    }
};

19. References

C++ provides references as a language feature. A reference acts as another name for an existing object or variable.

int number = 10;

int& ref = number;

ref = 20;

References are not part of the C language.

20. Exception Handling

C++ provides built-in exception handling using try, catch, and throw.

try {
    // Code
}
catch (...) {
    // Handle exception
}

C does not provide this C++ exception-handling mechanism.

21. Standard Library

Both C and C++ provide standard libraries, but C++ has a much broader set of standard library facilities, including containers, algorithms, iterators, strings, and other utilities.

The C++ Standard Template Library is commonly known as STL.

22. STL Containers in C++

C++ provides standard containers such as:

  • vector
  • list
  • deque
  • map
  • set
  • queue
  • stack
#include <vector>

std::vector<int> numbers = {10, 20, 30};

23. Strings

C commonly represents text using character arrays. C++ provides the std::string class as part of its standard library.

#include <string>

std::string name = "Rahul";

The C++ string class provides many convenient operations for handling text.

24. C vs C++ Syntax

Many basic statements look similar in C and C++. For example, variables and control statements use familiar syntax.

int age = 20;

if (age >= 18) {
    // Code
}

However, C++ adds many additional language features.

25. Comparison Table

Feature C C++
Programming Style Primarily procedural Procedural, object-oriented, generic
Classes No built-in classes Supported
Objects No built-in object model Supported
Inheritance Not a built-in class feature Supported
Function Overloading Not supported Supported
Templates Not supported Supported
References Not available Supported
Exception Handling No C++-style mechanism Supported
STL No Yes

26. Performance

Both C and C++ can produce highly efficient compiled programs. Performance depends on the implementation, compiler, algorithms, data structures, and how the program is written.

C++ provides additional abstractions while also allowing low-level programming techniques.

27. Applications of C

C is widely used in areas such as:

  • Operating-system components
  • Embedded systems
  • System programming
  • Device software
  • Low-level software

28. Applications of C++

C++ is used in many areas, including:

  • Game development
  • Game engines
  • Desktop applications
  • System software
  • Graphics applications
  • Embedded software
  • High-performance applications

29. When Learning C and C++

Learning C helps students understand procedural programming, memory, pointers, arrays, functions, and low-level programming concepts.

Learning C++ builds on many of these concepts and adds object-oriented, generic, and modern programming features.

A learner who understands the fundamentals of C can recognize many familiar concepts when beginning C++.

30. C vs C++ – Final Summary

C and C++ share many fundamental concepts, but C++ extends the programming model with classes, objects, inheritance, polymorphism, templates, references, exception handling, and a large standard library.

C
↓
Procedural Programming
↓
Functions + Structures + Pointers

C++
↓
Procedural Programming
+
Object-Oriented Programming
+
Generic Programming
+
Standard Library

Understanding the differences between C and C++ will make it easier to understand why C++ provides additional programming techniques while retaining many familiar C-style concepts.

📌 Key Points

  • C++ evolved from C.
  • C and C++ are separate programming languages.
  • C mainly follows a procedural programming approach.
  • C++ supports procedural, object-oriented, and generic programming.
  • C++ provides classes and objects.
  • C++ supports inheritance and polymorphism.
  • C++ supports function and operator overloading.
  • C++ provides templates for generic programming.
  • C++ provides references.
  • C++ provides C++-style exception handling.
  • C++ includes a large standard library and STL.
  • Both C and C++ can be used to create efficient compiled programs.

🧠 Quick Quiz

Question: Which feature is directly supported by C++ but not by C?