Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- // [ captures ] ( params ) { body }
- //
- [](){cout << "Shortest decleration " << endl;}();
- // [](int a, int b){ cout << "Parameters sum: " << a+b << endl;} (10,20);
- int sum =[](int a, int b){return a+b;} (10,20);
- cout << "Parameters sum: " << sum << endl;
- int a = 5;
- auto function = [a]() {cout << a << endl; }; // Passing A by value, a value won't change the expression
- function();
- a = 10;
- function();
- auto function2 = [&a]() {cout << a << endl;}; // Passing A by reference, change will occur
- function2();
- a = 20;
- function2();
- }
Add Comment
Please, Sign In to add comment