So today i was learning about c++ lambda functions. and i have some doubts.
Q.1) See this
why the output is 2?
Q.2) another question
Spoiler
tell me
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 156 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 135 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
Two Questions about c++ lambda functions. [Must Read]
So today i was learning about c++ lambda functions. and i have some doubts.
Q.1) See this
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.
Q.2) another question
function<int(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;
};
tell me
| Rev. | Lang. | By | When | Δ | Comment | |
|---|---|---|---|---|---|---|
| en3 |
|
Boring_Day | 2022-10-06 09:47:31 | 225 | ||
| en2 |
|
Boring_Day | 2022-10-06 06:58:39 | 38 | ||
| en1 |
|
Boring_Day | 2022-10-06 06:55:35 | 889 | Initial revision (published) |
| Name |
|---|


