⬅ Previous Next ➡

Introduction to C++

Introduction to C++
  • C++ is an extension of C that supports both procedural and object-oriented programming.
  • History: C++ was developed by Bjarne Stroustrup at Bell Labs (started as “C with Classes”).
  • Features: OOP (classes/objects), encapsulation, inheritance, polymorphism, function/operator overloading, templates (generic programming), fast execution.
  • Comparison with C: C is procedural; C++ adds OOP, references, classes, constructors/destructors, function overloading, and stronger type checking.
  • Program Structure: header includes, namespace, main() function, statements, return.
  • Compilation Process: source (.cpp) → compile → link → executable/run.
  • Basic I/O: use cin for input and cout for output (from iostream).
#include <iostream>
using namespace std;

int main() {
    int age;
    string name;

    cout << "Enter name: ";
    cin >> name;

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

    cout << "\nHello, " << name << "! Age: " << age << endl;
    return 0;
}
// Compilation (G++):
// g++ program.cpp -o program
// ./program
⬅ Previous Next ➡