So today i was learning about c++ lambda functions. and i have some doubts.↵
↵
Q.1) See this↵
↵
<spoiler summary="why the output is 2?">↵
↵
~~~~~↵
function<int(int,int)> sum = [&](int a, int b)↵
{↵
++a;↵
return a+b;↵
};↵
int a = 2, b = 3;↵
int s = sum(a, b);↵
cout << a << endl;// why it's 2 i have passed 'a' with refrence. how to pass it with refrence.↵
~~~~~↵
↵
↵
</spoiler>↵
↵
Q.2) another question↵
↵
<spoiler summary="Spoiler">↵
↵
~~~~~↵
function<voidint(int)> sum = [&](int a)↵
{↵
// some code↵
cout << get(2); // how can i use the get function?↵
return something;↵
};↵
↵
function<int(int)> get = [&](int v)↵
{↵
int b = sum(3);↵
return v;↵
};↵
~~~~~↵
↵
↵
</spoiler>↵
↵
tell me
↵
Q.1) See this↵
↵
<spoiler summary="why the output is 2?">↵
↵
~~~~~↵
function<int(int,int)> sum = [&](int a, int b)↵
{↵
++a;↵
return a+b;↵
};↵
int a = 2, b = 3;↵
int s = sum(a, b);↵
cout << a << endl;// why it's 2 i have passed 'a' with refrence. how to pass it with refrence.↵
~~~~~↵
↵
↵
</spoiler>↵
↵
Q.2) another question↵
↵
<spoiler summary="Spoiler">↵
↵
~~~~~↵
function<
{↵
// some code↵
cout << get(2); // how can i use the get function?↵
return something;↵
};↵
↵
function<int(int)> get = [&](int v)↵
{↵
int b = sum(3);↵
return v;↵
};↵
~~~~~↵
↵
↵
</spoiler>↵
↵
tell me