Codectionary / Developer documentation / C++

Start here to understand what C++ is, why it was created, how a program becomes an executable, and where its control over resources is useful.

File extension
.cpp · .hpp
Runs in
Compiled native applications

What C++ is

C++ (pronounced “C plus plus”) is a general-purpose programming language: it can be used to build many kinds of software, from small command-line tools to parts of large games and scientific systems. A C++ source file commonly ends in .cpp. The language gives you rules for writing the program; a compiler and other tools turn that source into something a computer can run. C++ is not itself a compiler or an operating system.

It is often chosen when a program needs predictable use of processing time or memory, access to system facilities, or integration with an existing C++ codebase. A first program needs none of the advanced machinery that makes C++ powerful. Begin with a complete, small program, then learn the language and its standard library one idea at a time.

From “C with Classes” to C++

Bjarne Stroustrup began work at Bell Labs in 1979 on what became C++. Its first form was called “C with Classes”. He wanted facilities for organising larger programs and expressing useful abstractions, while retaining the efficiency and systems access that made C valuable. In this context, an abstraction is a way to give a useful name and interface to a more complicated implementation, such as a container that manages its own storage.

The name C++ was adopted in 1983; the ++ echoes C’s increment operator and suggests an evolution of C. C++ was used inside AT&T that year, and a first commercial implementation appeared in 1985. The language then gained features such as templates and exceptions, followed by an international standard. This history explains both its close connection to C and why older C++ code can look very different from a modern tutorial.

How C++ relates to C

C++ grew from C and shares much of its syntax: braces enclose blocks, semicolons end many statements, and both languages use functions and familiar control flow. C++ adds its own type rules, classes, templates, references and standard-library facilities. C and C++ are separate languages with separate standards; a C file is not guaranteed to compile unchanged as C++, and a C++ program is not simply C with a few classes attached.

For example, a C-style array is available in C++, but a modern C++ program can often use std::vector to keep track of its elements and storage. That is a design choice, not a rule that every C API or low-level array must be replaced. When working with an existing C library or system interface, check its documented boundary instead of assuming the two languages are interchangeable.

The ISO standard and modern C++

The ISO C++ standard specifies the language and standard library so different compiler implementations have a shared target. It is a specification, not an installer or a promise that every compiler supports every feature immediately. C++98 was the first ISO standard. Later editions such as C++11, C++17, C++20 and C++23 added language and library facilities; C++23 is the current published edition (ISO/IEC 14882:2024) as of October 2026. Work on C++26 is in progress, so draft features should not be presented as universally available.

“Modern C++” describes an approach as much as a date: use the type system, standard containers, clear ownership and automatic cleanup where they fit. Older code often uses raw arrays and manual new/delete calls more heavily. Modern C++ still permits low-level operations when a task genuinely needs them, and maintaining an older codebase may require its existing style. Always check the language version selected by a project and the compiler’s feature support before copying an example.

How a C++ program becomes executable

A typical local workflow starts with human-readable source in one or more .cpp files. The toolchain processes included declarations, checks and compiles source into object files, then links those files with needed libraries to produce an executable for a target platform. Running that executable makes the processor carry out its instructions. Different toolchains may combine or optimise these stages, but “compile, link, run” is a useful beginner model. Unlike a web page’s JavaScript, ordinary C++ source is not run directly by a browser.

C++ is statically typed: the compiler knows the type of an expression, such as int for a whole number, and checks many mismatches before execution. In the first program below, int lessons = 3 declares a named integer value. Type deduction with auto can spare you from spelling some types, but the compiler still determines a type. Successful compilation does not prove the program is correct: bad input, out-of-range access and logic mistakes can still cause failures at runtime.

Several ways to organise a program

Procedural code uses functions and a sequence of operations. A small program might read temperatures, call a function that converts each value, then print a report. Object-oriented code uses classes to keep related state and operations together; a game might give a Player object a position and movement behaviour. Neither approach requires every calculation to become a class.

Generic programming writes reusable code that works with different types. A function template, for example, can describe an operation for several suitable value types, with the compiler producing the needed forms. C++ supports these styles together: a program may use plain functions, classes and templates in different places. Choose the structure that makes each responsibility clear rather than trying to use every language feature at once.

Memory, resources and performance

Memory holds program data while it runs. C++ gives developers choices about where values live, who owns a resource and when it is released. A resource can be memory, but also a file, socket or lock. A local object normally ends its lifetime when its scope ends; library types such as std::vector manage their own storage. RAII is the common C++ technique of tying resource cleanup to an owning object’s lifetime, so cleanup still happens when a function leaves early.

That control can avoid unnecessary allocations and help a program meet time or memory limits. It also brings responsibility: using an object after its lifetime, accessing outside an array or mishandling ownership can produce serious bugs. Prefer standard containers and ownership tools for ordinary work; raw pointers and manual allocation are not prerequisites for writing useful C++. Performance depends on the algorithm, data, compiler settings and hardware. Measure a real workload rather than assuming that every C++ program is faster than every program in another language.

Games, engines, graphics and rendering

Game engines may use C++ for simulation, physics, asset processing or systems that run frequently within a frame. Unreal Engine, for example, exposes C++ gameplay classes alongside its Blueprint tools. A game can combine C++ engine code with scripting, visual tools and other languages; learning C++ does not mean every game is written entirely in it.

Graphics and rendering software repeatedly transforms geometry, textures and pixels under a limited time budget. C++ can help organise these algorithms and control data layout, while graphics APIs and specialised GPU code perform other parts of the work. The useful lesson is to match the language and libraries to the part of the pipeline you are actually building.

Systems software, embedded devices and robotics

System components, browser engines, compilers and performance-sensitive infrastructure often need close interaction with operating-system interfaces or existing native libraries. C++ can provide that access while offering classes and standard containers. This does not mean every operating-system kernel is written in C++; kernels and services make their own choices, and some environments support only a restricted subset of C++.

An embedded controller might have limited memory and strict timing requirements. A robot may need to process sensor data and send commands at predictable intervals; ROS 2, for instance, has a C++ client library. C++ can fit those needs, but the available library, exceptions, memory allocation and deployment method depend on the device or robotics framework.

Scientific, financial and desktop software

High-performance computing and scientific software often repeat calculations over large datasets or simulations. C++ offers reusable numeric code with control over storage and parallel execution. CERN’s ROOT data-analysis framework is a concrete C++ example, and it also offers Python interfaces. Teams frequently combine languages so researchers can explore data at a higher level while performance-sensitive parts use C++.

Financial and other low-latency systems may use C++ where response time and resource use need careful control, such as processing market messages. That choice brings a need for measurement, testing and operational safeguards; the language alone cannot guarantee a particular latency. Desktop applications can use C++ frameworks such as Qt for windows, controls and platform integration. These are examples of roles C++ can play, not claims that every scientific, financial or desktop application uses it.

Advantages and limitations

C++ offers a mature ecosystem, portability of source across supported toolchains, several useful programming styles, and detailed control over performance and resources. It works well with existing native code and can serve projects that must run on specific hardware. Developers continue to use it both for these capabilities and because substantial, long-lived systems already depend on C++ libraries and expertise.

The costs are real: builds and toolchain configuration can be demanding; the language has a large set of rules and features; and memory or lifetime mistakes can be difficult to diagnose. A source file may need changes for another operating system or compiler even when it follows the standard. If a small script or web interaction does not need these capabilities, another language may be simpler. Choose C++ because its strengths solve a concrete problem, not because it is always the fastest or most “advanced” option.

Read your first complete program

The example below prints Lessons ready: 3 to a terminal. #include <iostream> makes standard input/output declarations available. main is the function where this ordinary console program starts. The braces hold its statements. int lessons = 3 creates a typed value; std::cout sends text and that value to standard output. The newline character moves the cursor to the next line, and return 0 reports successful completion to the host environment.

Save the code as main.cpp. Once you have a suitable C++ compiler, compile it for your platform and run the resulting executable; the exact command differs between toolchains. Change 3 to 4, compile again and run again. Recompilation matters: an existing executable does not change merely because you edited the source file. This short experiment shows the source-to-executable workflow without requiring you to learn pointers, classes or build systems first.

main.cpp

#include <iostream>

int main() {
  int lessons = 3;
  std::cout << "Lessons ready: " << lessons << '\n';
  return 0;
}

Where to go next

Begin with variables and types, then decisions, loops and functions. After you can read a small complete program, learn standard containers such as std::vector before exploring manual memory management. Classes, templates and ownership ideas make more sense when you have a task that needs them. Keep a compiler’s error messages nearby: read the first relevant error, correct it and rebuild.

A small command-line score reporter is a good first project. Store a few scores, calculate a total and print a result. It gives practice with values, loops and functions without a game engine or large framework. If you have not installed a compiler, choose the guide for your operating system first; then use the dedicated first-program walkthrough to build and troubleshoot a complete example.

Syntax

#include <iostream>

int main() {
  int lessons = 3;
  std::cout << "Lessons ready: " << lessons << '\n';
  return 0;
}

Examples

Print a message from a complete C++ program

Save as main.cpp, compile it with a local C++ toolchain, then run the generated executable.

#include <iostream>

int main() {
  int lessons = 3;
  std::cout << "Lessons ready: " << lessons << '\n';
  return 0;
}
  1. The goal is to print the message Lessons ready: 3. This is a complete console program, not a fragment to paste into another function.
  2. #include <iostream> provides std::cout. int main() names the entry function; braces enclose its statements and each statement ends with a semicolon.
  3. int lessons = 3 stores a whole number. The << operators send the label, the number and a newline to standard output, so the terminal shows one line of text.
  4. return 0 reports successful completion. Change lessons to 4, compile again and rerun; the output changes to Lessons ready: 4. A tool that prints counts or status messages uses the same basic pattern.

C++: background & uses

Used for
Game engines, Native applications, Systems software
Created by
Bjarne Stroustrup at Bell Labs
First released
1985 · first commercial release
Version / standard
C++23

Current published ISO standard (ISO/IEC 14882:2024). Compiler support varies.

In the real world

  • Google: The Chromium browser project
  • Epic Games: Unreal Engine development
  • Adobe: Documented use in Photoshop

Facts checked 8 September 2026. Product links describe documented uses.

Best practices

  • Start with complete, small programs and change one value at a time before adding new language features.
  • Use standard-library containers and clear ownership for ordinary tasks; reserve manual resource handling for a demonstrated need.
  • Check the compiler and language version required by an existing project before using a newer feature.
  • Measure performance and test correctness on the real workload instead of relying on a language label.

Runtime & versions

Compiled native applications. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

ISO C++ resources

Specifications & further reading