“Know how to solve every problem that has been solved.” “What I cannot create, I do not understand.” — Richard Feynman

Lambda

Programming

Audited·on 2026-05-14·short read
What you need to know first 1 concepts, 1 layers

The requisite-knowledge inventory for this page, bottom-up: the primitives at the base, combined upward until you reach what this page assumes. Skim the layers you already own; start wherever the ground gets unfamiliar.

  1. base
  2. you are here

This program demonstrates lambda expressions (anonymous functions) in C++, which allow defining functions inline without a name.

Implementation

#include <iostream>

int main() {
    auto add = [](int a, int b) { return a + b; };
    std::cout << "Sum: " << add(3, 7) << std::endl;
    return 0;
}

Lambda Syntax

A lambda expression has the following syntax:

[capture](parameters) -> return_type { body }

Key Concepts

Output

Sum: 10