Introduction to C++

C++ is a fast, compiled language that combines C's direct control over the machine with powerful tools for building large programs: classes, templates, a rich standard library and automatic resource management. It runs game engines, browsers, databases, trading systems and much of the software where performance matters most.

Where C++ is used

  • Games and graphics — Unreal Engine and most AAA game engines, 3D tools, VR.
  • Browsers and operating system components — Chrome, Firefox and large parts of Windows and macOS.
  • Infrastructure — databases such as MySQL and MongoDB, compilers (LLVM), and high-performance servers.
  • Finance and science — low-latency trading, simulations, machine-learning frameworks such as the cores of PyTorch and TensorFlow.
  • Embedded and real-time systems — cars, robots, drones, medical devices.

A first look

C++
#include <iostream>
#include <string>
#include <vector>

int main() {
    std::vector<std::string> languages{"C", "C++", "Rust"};
    for (const auto& name : languages) {
        std::cout << "Hello from " << name << "!\n";
    }
}
Output
Hello from C!
Hello from C++!
Hello from Rust!

This program stores three strings in a vector — a list that manages its own memory — and prints a greeting for each. Lesson 3 explains every part.

C++ and C

C++ began as "C with classes", and almost all C code is still valid C++. But modern C++ is written very differently from C:

TaskC styleModern C++ style
Textchar arrays and strcpystd::string
ListsArrays plus malloc/reallocstd::vector
Memorymalloc and free by handContainers and smart pointers that free themselves
ErrorsReturn codesExceptions, std::optional, std::expected
Generic codeMacros, void *Templates and concepts

You don't need to know C to take this course. If you do, the C course gives useful background on memory and pointers.

What makes C++ special

  • Zero-overhead abstractions. High-level features like classes, templates and algorithms compile down to code as fast as hand-written low-level code.
  • RAII. Objects clean up after themselves when they go out of scope — memory, files, locks — without a garbage collector.
  • Multi-paradigm. Procedural, object-oriented, generic and functional styles all work, and mix freely.
  • Huge ecosystem. Decades of libraries, tools and expertise.

The trade-off is complexity: C++ is a big language with sharp edges inherited from C. This course focuses on the modern, safer subset you should actually use.

A short history

Bjarne Stroustrup started "C with Classes" at Bell Labs in 1979; it was renamed C++ in 1983 (++ is the increment operator). Since the first ISO standard in 1998 the language has been updated every three years:

StandardHighlights
C++98/03The first standard: classes, templates, the STL containers and algorithms
C++11"Modern C++": auto, lambdas, move semantics, smart pointers, range-for, threads
C++14 / C++17Refinements; optional, variant, string_view, structured bindings
C++20Concepts, ranges, std::format, span, coroutines, modules
C++23std::print, std::expected, more ranges
C++26In progress: reflection, contracts and more

This course teaches C++20, which current GCC, Clang and MSVC support well, and covers the newer C++23 additions in lesson 50.

How this course works

Every example was compiled with a real compiler (Clang 17, using -std=c++20 -Wall -Wextra -pedantic) and run, and the output shown is exactly what it printed. The Try it yourself boxes let you edit an example and copy it to compile on your own computer — set that up in the next lesson.

Try it yourself

Add your own favourite languages to the list and run it again.

Try it yourself · main.cpp
Edit the code, copy it into main.cpp, then compile and run it with c++ -std=c++20 -Wall main.cpp -o main && ./main. How to set up a C++ compiler
Output
I want to learn C++
I want to learn Python
I want to learn JavaScript