What is C++? Introduction and Overview
What is C++?
C++ is a general-purpose, compiled, statically-typed programming language created by Bjarne Stroustrup in 1979 at Bell Labs as an extension of C. Originally called "C with Classes", it was renamed to C++ in 1983 — the ++ being C's increment operator, symbolising an improvement over C.
C++ combines low-level memory control with high-level abstractions (OOP, templates, STL). It powers operating systems, game engines, browsers, databases, and embedded systems — anywhere performance and control matter.
History of C++
| Year | Milestone |
|---|---|
| 1979 | Bjarne Stroustrup begins "C with Classes" at Bell Labs |
| 1983 | Renamed to C++; virtual functions and function overloading added |
| 1985 | First commercial release; "The C++ Programming Language" book published |
| 1998 | C++98 — first ISO standard; STL included |
| 2011 | C++11 — major update: auto, lambda, smart pointers, move semantics, threads |
| 2014 | C++14 — generic lambdas, make_unique |
| 2017 | C++17 — structured bindings, std::optional, std::variant, filesystem |
| 2020 | C++20 — concepts, ranges, coroutines, modules, std::format |
| 2023 | C++23 — std::print, std::expected, flat_map |
Features of C++
C++ vs C — Key Differences
| Feature | C | C++ |
|---|---|---|
| Paradigm | Procedural only | Procedural + OOP + Generic + Functional |
| Classes / Objects | No | Yes — core feature |
| Inheritance | No | Yes (single, multiple, virtual) |
| Function overloading | No | Yes |
| Operator overloading | No | Yes |
| Templates | No | Yes — generic programming |
| Exception handling | No (use errno) | Yes — try/catch/throw |
| Standard I/O | printf / scanf | cout / cin (streams) |
| String type | char array only | std::string class |
| Memory management | malloc / free | new / delete + smart pointers |
| Namespaces | No | Yes — prevents name collisions |
| References | No | Yes — safer alias for variables |
| bool type | No (use int) | Yes — native bool |
| File extension | .c | .cpp / .cxx / .cc |
Structure of a C++ Program
Every C++ program follows a predictable structure. Understanding each part is essential before writing any code.
// 1. Preprocessor directive — includes the iostream header
#include <iostream>
// 2. Using declaration — avoids writing std:: prefix everywhere
using namespace std;
// 3. main() — entry point of every C++ program
// int return type: 0 = success, non-zero = error
int main() {
// 4. cout — standard output stream
// << — stream insertion operator
// endl — newline + flush buffer (\n is faster)
cout << "Hello, World!" << endl;
// 5. Variables — must declare type before use
int age = 25;
double salary = 55000.50;
string name = "Alice";
cout << name << " is " << age << " years old." << endl;
// 6. return 0 — signals successful program termination
return 0;
}
/*
* Output:
* Hello, World!
* Alice is 25 years old.
*/
// A C++ program with a class — the OOP way
#include <iostream>
#include <string>
using namespace std;
// Class definition — blueprint for objects
class Car {
private: // only accessible inside the class
string brand;
int year;
public: // accessible from outside
// Constructor — called when object is created
Car(string brand, int year) : brand(brand), year(year) {}
// Member function (method)
void display() const {
cout << year << " " << brand << endl;
}
};
int main() {
Car c1("Toyota", 2022); // create object on stack
Car c2("BMW", 2024);
c1.display(); // 2022 Toyota
c2.display(); // 2024 BMW
return 0;
}
C++ Compilation Model
Unlike interpreted languages (Python, JavaScript), C++ is compiled — source code is translated to machine code before running. The process has four stages:
| Stage | Tool | Input | Output | What happens |
|---|---|---|---|---|
| 1. Preprocessing | cpp | .cpp | .i | Expands #include, #define, removes comments |
| 2. Compilation | g++/clang++ | .i | .s | Translates C++ to assembly language |
| 3. Assembly | as | .s | .o | Converts assembly to object (machine) code |
| 4. Linking | ld | .o + libs | executable | Combines object files and libraries into final program |
# Compile
g++ hello.cpp -o hello
# Compile with C++17 standard and all warnings (recommended)
g++ -std=c++17 -Wall -Wextra hello.cpp -o hello
# Run on Linux/macOS
./hello
# Run on Windows
hello.exe
# See each compilation stage
g++ -E hello.cpp -o hello.i # preprocessing only
g++ -S hello.cpp -o hello.s # compile to assembly
g++ -c hello.cpp -o hello.o # compile to object file
g++ hello.o -o hello # link to executable
Applications of C++
| Domain | Examples |
|---|---|
| Operating Systems | Windows kernel, parts of Linux, macOS |
| Game Engines | Unreal Engine, CryEngine, id Tech |
| Web Browsers | Google Chrome (V8 engine), Mozilla Firefox |
| Databases | MySQL, MongoDB, SQLite |
| Compilers / Interpreters | GCC, Clang, Python interpreter (CPython) |
| Embedded Systems | Arduino, automotive ECUs, IoT devices |
| Finance / Trading | High-frequency trading systems, Bloomberg Terminal |
| Graphics / Multimedia | Adobe Photoshop, Autodesk Maya, OpenCV |
| Machine Learning | TensorFlow core, PyTorch C++ backend |
Level Up Your C plus plus Skills
Master C plus plus with these hand-picked resources