Skip to content

Instantly share code, notes, and snippets.

@jitpaul

jitpaul/Lambdas1 Secret

Last active April 26, 2018 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitpaul/c79c618131b221c27f2281db92e40f8c to your computer and use it in GitHub Desktop.
Save jitpaul/c79c618131b221c27f2281db92e40f8c to your computer and use it in GitHub Desktop.
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