title: Using lambda expressions by value capture
body: <p>Quick query regarding usage of lambda captures, particularly about "by value capture". Here is my code:</p>
  
  <pre><code>class carl{
  public:
      int x;      
      void sayhi();
  };
  
  
  void carl::sayhi(){
  
      auto c1 = [=](){            //capture by value
      std::cout&lt;&lt;&amp;x&lt;&lt;std::endl;   
      x = 10;                     // access the copy?
      };
  
      c1();
      std::cout&lt;&lt;&amp;x&lt;&lt;std::endl;   // same address as the one inside lambda
      std::cout&lt;&lt;x&lt;&lt;std::endl;    //prints 10 now WHY????
  }
  
  int main(int argc, char** argv) {
  
  carl x;
  x.sayhi();
  
  return 0;
  }
  </code></pre>
  
  <p>My issue is that, are "by value" captures in lambda supposed to affect the original? aren't they supposed to make a copy? From my example, I used <code>[=]</code> so my lambda will make a copy of the variable within that class's scope. I tried accessing <code>x</code> and it directly altered x's original value. I tried researching about it and from my own words: it's stated that accessing a variable inside a lambda which has a <code>[=]</code> capture will access the lambda's local copy.</p>
  
  <p>Edit: I actually get the feeling that I am trying to access <code>this</code> pointer which is also captured from <code>[=]</code>. Therefore, accessing <code>x</code> from my code is like accessing <code>this-&gt;x</code> which is the same pointer as my original one. Please correct me if I'm wrong.</p>