Lambda

Programming

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