title: When are variables removed from memory in C++?
body: <p>I've been using C++ for a bit now. I'm just never sure how the memory management works, so here it goes:</p>
  
  <p>I'm first of all unsure how memory is unallocated in a function, ex:</p>
  
  <pre><code>int addTwo(int num)
  {
      int temp = 2;
      num += temp;
      return num;
  }
  </code></pre>
  
  <p>So in this example, would temp be removed from memory after the function ends? If not, how is this done. In C# a variable gets removed once its scope is used up. Are there also any other cases I should know about?</p>
  
  <p>Thanks</p>