Two Questions about c++ lambda functions. [Must Read]
Difference between en2 and en3, changed 225 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="
SpoilerThis is giving me runtime error why?">↵

~~~~~↵
        function<int(int)> 
sum = [&](int a)get2;
        
{
        
    // some code↵
            cout << get(2); // how can i use the get function?↵
            return something;↵
        }
cout << get2(3);↵

       
 function<int(int)> get2 = [&](int va)↵
        {↵
            int b = sum(3);↵
            return va;↵
        };↵


~~~~~↵


</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)