Reference

Programming languages

Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.

Scope and conventions

TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.

Functions

Define and call a function

C++

The return type comes first, followed by the name and typed parameters. void declares no returned value.

Fragment

Function declaration, then a call fragment inside main.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
int twice(int n) {
    return n * 2;
}

auto result = twice(6);

Find the entry point

C++

A hosted executable starts at main. Returning 0 signals success; reaching the end of main also returns 0.

Fragment

Complete main.cpp.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <iostream>

int main() {
    std::cout << "north\n";
}

Recognize custom types and methods

C++

class members are private by default; public: exposes members. struct defaults to public. Methods access instance fields. LinePrinter, push and finish are exercise-defined.

Fragment

Class declaration at file scope; value statements inside a function.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
class Counter {
    int value = 0;

public:
    void add() {
        value += 1;
    }
};

// Inside main:
Counter c;
c.add();

Construct a custom value

C++

A constructor has the class name and no return type. The : value(start) member initializer initializes the field before the body runs. explicit prevents implicit conversions through this constructor. Token item{24} creates an automatic object without a new expression.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
struct Token {
    int value;

    explicit Token(int start)
        : value(start) {
    }
};

Token item{24};

Pass a function or capture a value

C++

[] introduces a lambda; its capture list chooses how outside locals are retained. [factor] copies factor; [&factor] borrows it and requires a valid lifetime. mutable permits changes to captured copies.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
int factor = 3;
auto scale = [factor](int n) {
    return n * factor;
};

int result = scale(2);

Recognize defaults and variable arguments

C++

Default arguments fill omitted trailing arguments; overloads are another facility. Variadic templates accept parameter packs. A C-style ... function has different type-safety rules and is not equivalent to a rest array.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
int scale(int value, int factor = 2) {
    return value * factor;
}

int defaulted = scale(5);
int explicitFactor = scale(5, 3);