Simple Lambda function
In this article, I write a c++ program using lambda.
This lambda function squares the input value.
The lambda is assigned to a variable. By calling this variable twice, the code in the body of the lambda gets executed.
#include <iostream>
using namespace std;
int main()
{
auto square = [](float x){
return x*x;
};
cout << "Output 1: " << square(5.10) << endl;
cout << "Output 2: " << square(6.10) << endl;
return 0;
}
The output is
💡
Output 1: 26.01
💡
Output 2: 37.21