Example & Tutorial understanding programming in easy ways.

Define lambda expression in C++

Lambda Function:
Basically, in C++ lambda expression are used to write the inline function.
-Return type of lanbda expression are evaluted by compiler itself.

Syntax-
capture_clause(parameters)->return-type
{
definition of method
}

program:

#include < bits/stdc++.h>
using namespace std;
//Display vector function
void printVector(vector< int> v)
{
// lambda expression to print vector
for_each(v.begin(), v.end(), [](int i)
{
std::cout << i << " ";
});
cout << endl;
}
int main()
{
vector v {4, 1, 3, 5, 2, 3, 1, 7};
printVector(v);
}


output-

4 1 3 5 2 3 1 7




Read More →