title: Is it efficient to declare a variable in a loop?
body: <p>If I do one of the following (which I assume are equivalent for the purpose of this question)</p>
  
  <pre><code>for(int i=0; i&lt;A; i++)
  {
    //... do stuff
    for(int j=0; j&lt;B; j++)
    {
      //... do stuff
    }
    //... do stuff
  }
  
  for(int i=0; i&lt;A; i++)
  {
    int j;
    //... do stuff
  }
  </code></pre>
  
  <p>Does the variable <code>j</code> get recreated on the stack every loop (is the <code>SP</code> constantly being updated every loop), or is the compiler smart enough to know how many local variables a function might have at one time, and then makes room for all of them on the stack at function entry?</p>
  
  <p>I understand that this is theoretically compiler-dependent, but I assume simple things like this are common across all major compilers. If not, does someone know specifically about <code>GCC</code> and <code>VC++</code> compilers?</p>