C++ Introduction
What C++ is, where it is used (games, engines, HFT), and compiling your first program with g++/clang++.
What is C++?
C++ is a general-purpose, compiled, statically-typed language created by Bjarne Stroustrup at Bell Labs starting in 1979 as "C with Classes" — C extended with object-oriented features. It was renamed C++ in 1983 and has been standardized by ISO since 1998 (C++98), with a major revision roughly every three years since: C++11, C++14, C++17, C++20, and C++23.
C++ keeps C's core philosophy — trust the programmer, and don't pay at runtime for a feature you don't use ("zero-cost abstractions") — while layering on classes, templates, exceptions, and, in modern versions, smart pointers, lambdas, concepts, and ranges. The result is a language that compiles to native machine code with no garbage collector and no managed runtime, but that can still express high-level abstractions cheaply.
Why C++ still matters
Whenever software needs to be both extremely fast and give the programmer direct control over memory layout and hardware, C++ is usually in the room:
- Games and game engines — Unreal Engine, most AAA titles, and the engines behind them are C++.
- Browser engines — Chromium/Blink's rendering and JavaScript engine internals, Firefox's Gecko.
- High-frequency trading (HFT) — where microseconds of latency translate directly into money, and a stop-the-world garbage collector pause is unacceptable.
- Operating systems and drivers — large parts of Windows, macOS/iOS frameworks, and countless embedded/RTOS components.
- Databases — MySQL, MongoDB's storage engine, ClickHouse.
- Real-time and embedded systems — robotics, audio/video processing, automotive software.
The common thread across all of these: predictable performance with no GC pauses, and fine-grained control over exactly how memory is laid out and when it's released.
Compiling a C++ program
C++ is compiled ahead of time to native machine code — there's no bytecode or interpreter involved at runtime. The two compilers you'll encounter almost everywhere are GCC's g++ and LLVM's clang++; both accept largely the same command-line flags.
g++ --version
clang++ --version
A .cpp file is a translation unit: the compiler preprocesses it (expanding #includes and macros), compiles it to an object file (.o), and then the linker combines object files (and libraries) into a final executable. For a single-file program you don't need to think about this pipeline explicitly — one command does all three steps.
Hello, World
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
g++ -std=c++20 -Wall -Wextra -o hello hello.cpp
./hello
Hello, World!
#include <iostream>pulls in the standard input/output stream library.std::cout("character output") is the standard output stream;<<is the stream-insertion operator.- Everything from the standard library lives in the
stdnamespace, which is why it'sstd::cout, not justcout. int main()is the program's entry point — the OS calls this function first. Returning0signals success; any other value signals an error to the calling shell or process.-std=c++20tells the compiler which language standard to compile against — compilers often default to an older standard, so it's worth setting explicitly.-Wall -Wextraturns on a wide set of compiler warnings. Always compile with warnings enabled — many classes of C++ bugs (uninitialized variables, signed/unsigned comparisons, shadowed variables) are caught for free here.
Which standard should you target?
This track uses C++20/23 idioms throughout — auto, range-based for, smart pointers, structured bindings — because that's what modern, professional C++ looks like today. You'll still encounter plenty of older C++03/11-style code in the wild (and in interviews, asked about for historical context), but new code should default to modern idioms rather than raw new/delete and manual loops.
Common mistakes
- Forgetting
-std=c++20(or newer) and unknowingly compiling against an older default standard, silently losing access to newer language features. - Writing "C with a few classes bolted on" — avoiding every modern C++ feature (smart pointers, RAII, the standard library containers) and reaching for raw arrays and manual
new/deleteout of habit. - Skipping
-Wall -Wextra— several categories of real bugs produce a compiler warning long before they'd ever cause a crash.
Interview questions
Q: What does "zero-cost abstraction" mean in C++? It means a higher-level language feature (classes, templates, iterators) compiles down to code that's just as fast as the equivalent hand-written low-level code would be — you don't pay a runtime performance penalty just for using the abstraction, and you don't pay for a feature at all if you never use it.
Q: Name a few domains where C++ is still the dominant choice, and explain why. Game engines, browser engines, HFT trading systems, and embedded/real-time software — all of them need predictable low-latency performance with no garbage-collector pauses, plus direct control over memory layout, which C++ provides while still allowing high-level abstractions.