Home › C++ Tutorial › C++ lambda
C++ lambda
Small unnamed functions.
Syntax: [capture](params){ body }. Capture outside variables by value [=] or by reference [&].
Example code
#include <iostream>
using namespace std;
int main() {
int k = 3;
auto mul = [k](int x) { return x * k; };
cout << mul(5) << endl;
return 0;
}