C++

On this page 8

C++ is a compiled, statically typed, general-purpose programming language that extends C with classes, templates, exceptions and a large standard library, while keeping direct control over memory and hardware. Among programming languages, it is the standard choice where performance, predictable latency and fine-grained resource control matter more than development speed.

Bjarne Stroustrup began the language at Bell Labs in 1979 as C with Classes, and it was renamed C++ in 1983. It has been standardized by ISO since 1998, and today it powers game engines, browsers, databases, trading systems, embedded devices and much of the infrastructure that other languages run on.

How C++ works: compilation and the zero-overhead principle

C++ source code is compiled ahead of time into native machine code for a specific processor and operating system. The build passes through the preprocessor, the compiler, which translates each source file into an object file, and the linker, which combines object files and libraries into an executable.

The language is designed around the zero-overhead principle: features a program does not use should cost nothing, and features it does use should be as efficient as hand-written lower-level code. Templates, inline functions and compile-time evaluation with constexpr let much of the abstraction disappear before the program runs.

There is no garbage collector in standard C++. Objects are created on the stack, where they are destroyed automatically at the end of their scope, or on the heap, where their lifetime must be managed, ideally by smart pointers rather than manual new and delete.

Key language features and paradigms

C++ is a multi-paradigm language: it supports procedural, object-oriented, generic and increasingly functional styles in the same program. This breadth is a strength for experts and a source of complexity for newcomers.

FeatureWhat it providesTypical use
Classes and inheritanceEncapsulation and polymorphismModeling domain objects, interfaces
RAIIResources released when objects go out of scopeFiles, locks, memory, sockets
TemplatesGeneric code resolved at compile timeContainers, algorithms, libraries
Smart pointersunique_ptr and shared_ptr ownershipSafe heap memory management
Move semanticsTransfer of resources without copyingEfficient return of large objects
Standard Template LibraryContainers, iterators, algorithmsVectors, maps, sorting, searching
Concepts and rangesConstrained templates, composable pipelinesClearer generic code since C++20
Core C++ features and their purpose

RAII, short for resource acquisition is initialization, is the most important C++ idiom. Tying every resource to an object’s lifetime means cleanup happens automatically, even when an exception is thrown, which removes whole classes of leaks.

C++ standards and their evolution

The ISO committee now publishes a new C++ standard every three years. Each revision adds features while keeping very strong backward compatibility, so code written decades ago usually still compiles.

StandardNotable additionsSignificance
C++98 and C++03First ISO standard, STLEstablished the language baseline
C++11auto, lambdas, move semantics, smart pointers, threadsStart of modern C++
C++14 and C++17Generic lambdas, optional, variant, filesystemRefinement and library growth
C++20Concepts, ranges, coroutines, modulesLargest update since C++11
C++23expected, print, more ranges supportUsability and library improvements
Major C++ standard revisions

Compiler support arrives gradually. GCC, Clang and Microsoft Visual C++ implement most features soon after standardization, but some, such as modules, took years to become practical in real build systems.

C++ compared with neighboring languages

C++ competes with languages that occupy similar systems and performance niches. The main distinctions concern memory safety, runtime model and ecosystem maturity.

LanguageMemory managementSafety guaranteesTypical domain
CManualMinimalKernels, firmware, small embedded systems
C++Manual plus RAII and smart pointersPartial, depends on disciplineEngines, browsers, high-performance systems
RustOwnership checked by the compilerMemory safety by defaultSystems code where safety is critical
Java and C#Garbage collectionMemory safe, managed runtimeEnterprise and application software
GoGarbage collectionMemory safe, simple concurrencyNetwork services, cloud tools
C++ and related languages

The strongest argument against C++ is memory unsafety: buffer overflows and use-after-free errors remain possible, and they account for a large share of serious security vulnerabilities in native software. The strongest argument for it is the unmatched body of existing code, libraries and tools.

Where C++ is the right choice

C++ fits projects that need maximum performance, deterministic resource release or direct hardware access, and that can afford experienced developers. It is less suitable for quick business applications, where managed languages deliver results faster.

Project typeIs C++ a good fitReason
Game engine or real-time graphicsYesFrame-time control and mature tooling
Low-latency tradingYesPredictable timing without garbage collection pauses
Embedded device with an RTOSOftenEfficient code with abstractions, subset rules
Extending an existing C++ codebaseYesInteroperability and team knowledge
New security-critical system componentConsider RustCompiler-enforced memory safety
Internal business web applicationRarelyManaged languages are faster to build with
Decision guide for choosing C++

Teams that adopt C++ today usually define a modern subset: a minimum standard such as C++17 or C++20, a ban on raw owning pointers, mandatory compiler warnings and sanitizers in continuous integration and an agreed style guide. Such rules keep the language’s power while reducing the risk of undefined behavior and make large codebases easier to maintain across teams.

Common pitfalls in C++

Most C++ problems come from undefined behavior, situations where the standard places no requirements on what the program does. A program with undefined behavior may work in testing and fail unpredictably in production after a compiler upgrade.

  • Raw new and delete lead to leaks and double frees; prefer smart pointers and containers.
  • Dangling references appear when code keeps pointers to objects that have already been destroyed.
  • Data races occur when threads share data without synchronization.
  • Very long template error messages slow debugging; concepts in C++20 make them clearer.
  • Sanitizers, static analysis and compiler warnings set to high levels catch many of these errors early.

A non-technical view

C++ is a programming language for software that has to be very fast and very efficient. Video games, web browsers and the control systems inside machines are often written in it.

It gives programmers close control over memory and hardware. This is a bit like driving a car with a manual gearbox. The control allows excellent performance. It also makes mistakes easier, so C++ rewards careful and experienced developers.

A concrete example

A studio building a racing game needs every frame rendered within about 16.7 milliseconds to reach 60 frames per second. Its engine is written in C++, using custom memory allocators so that no unpredictable pauses occur during a race, and templates to generate fast physics code for different vehicle types.

When profiling shows that collision checks take too long, engineers restructure the data into contiguous arrays that the processor cache handles efficiently. Frame times drop by several milliseconds on target consoles, and stuttering during busy race starts disappears, which shows the kind of low-level tuning C++ makes possible.