title: Overhead to declaring a variable within a function run in a loop?
body: <p>There has been asked <a href="https://stackoverflow.com/questions/982963/is-there-any-overhead-to-declaring-a-variable-within-a-loop-c">that</a> question already. The answer was "Stack space for local variables is usually allocated in function scope." and so there is no difference in overhead in declaring variables outside/inside of a loop.</p>
  
  <p>Now, imagine that we have a snippet with a function inside of the loop:</p>
  
  <pre><code>void do_sth(int &amp;i) {int var=i+1;}
  int i = 0;
  while(i &lt; 100)
  {
      do_sth(i);
      i++;
  }
  </code></pre>
  
  <p>And a second snippet with a variable declared outside:</p>
  
  <pre><code>int i = 0;
  int var;
  while(i &lt; 100)
  {
      var = i+1;
      i++;
  }
  </code></pre>
  
  <p>My question is - what is the overhead in case of the first snippet in a practical scenario (with a modern compiler)? If indeed there is an overhead, then how big is it? Is it comparable with, say, doing extra addition (operator+) on integers in each step of the loop?</p>