C++ vs C

C and C++ are closely related programming languages. C++ was developed as an extension of the C programming language. While both languages share many similarities, C++ introduces additional features such as object-oriented programming and a larger standard library.

Key Differences Between C and C++

FeatureCC++
Programming StyleProcedural programming languageSupports both procedural and object-oriented programming
FocusFocuses mainly on functions and proceduresFocuses on objects and classes
Object-Oriented FeaturesDoes not support object-oriented programmingSupports OOP features such as classes, inheritance, and polymorphism
Standard LibrarySmaller standard libraryLarger standard library including STL
Data SecurityLess secure because it does not support data hidingProvides data hiding and encapsulation
Exception HandlingDoes not support exception handlingSupports exception handling
Function OverloadingNot supportedSupported

Example in C

#include 

int main() {
    printf("Hello World");
    return 0;
}

Example in C++

#include 
using namespace std;

int main() {
    cout << "Hello World";
    return 0;
}

Summary

C is mainly used for system programming and low-level applications. C++ extends C by adding object-oriented features, making it suitable for both system-level and large-scale application development.

Next Topic

Next, learn about Installing C++.