Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Introduced in C++11, lambdas are inline, anonymous functions that can capture variables from their surrounding scope.
[capture](parameters) -> return_type {
// function body
};sort(v.begin(), v.end(), [](int a, int b) {
return a > b; // Descending order
});[]: No capture. [&]: Capture by reference. [=]: Capture by value.
Great for short-lived logic that doesn't deserve a full function definition.