C++workingcpp17
Lambdas and captures
Inline, anonymous functions that can grab variables from the enclosing scope by value or by reference.
[capture](params){ body } builds a callable on the spot — the capture list decides which surrounding variables it sees, mutable lets it keep state, and auto parameters make it generic.
Define and call a lambda
C++intro0ms
2516hello
Reference · output compiled offline, not runnable in-browser
square behaves like any callable — square(5) is 25 and nesting square(square(2)) squares 4 to 16, while the capture-free greet shows a lambda needs neither parameters nor a capture list.