Skip to content

Instantly share code, notes, and snippets.

@jitpaul

jitpaul/Lambdas1 Secret

Last active April 26, 2018 07:25
Embed
What would you like to do?
Lambdas
#include <iostream>
using namespace std;
int main(){
int multiplier = 25;
/*Takes an integer input by reference and multiplies it by 2.*/
auto func1 = [](int& a){a *=2;};
/*Takes an integer input by value, multiplies it by 2 and returns the result.*/
auto func2 = [](int a)->int {a *=2; return a;};
/*Takes an integer input by value, multiplies it by multiplier whose value is captured from the outer scope and returns the result.*/
auto func3 = [multiplier](int a)->int{a *= multiplier; return a;};
int temp = 5;
func1(temp);
cout << temp<<endl;
cout << func2(temp)<<endl;
cout << func3(temp)<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment