example2_lambda_with_parameters.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include <iostream>

int main() {
    auto add = [](int a, int b) -> int {
        return a + b;
    };

    int result = add(3, 4); // Calls the lambda with arguments 3 and 4
    std::cout << "Result: " << result << std::endl; // Outputs: Result: 7

    return 0;
}
Back to lambda