Two Questions about c++ lambda functions. [Must Read]
Difference between en1 and en2, changed 38 character(s)
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

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Boring_Day 2022-10-06 09:47:31 225
en2 English Boring_Day 2022-10-06 06:58:39 38
en1 English Boring_Day 2022-10-06 06:55:35 889 Initial revision (published)