title: Why does this program produce odd output when the variable is uninitialized?
body: <pre><code>int main() {
      int j = 0;
      int i = 0;
      for (j = 0; j &lt; 5; j++) {
          printf("Iteration %d :  %d ", j + 1, i);
          int i;
          printf("%d", i);
          i = 5;
          printf("\n");
      }
  }
  </code></pre>
  
  <p>The above code generates the following output:</p>
  
  <pre><code>Iteration 1 :  0 0
  Iteration 2 :  0 5
  Iteration 3 :  0 5
  Iteration 4 :  0 5
  Iteration 5 :  0 5
  </code></pre>
  
  <p>I'm not able to understand why the second <code>printf</code> value in iterations 2,3,4,5
  is 5.</p>
  
  <p>My understanding of why the first value is 0 in each iteration is that the scope of <code>i</code> in the <code>for</code> loop is local and it is destroyed as soon as we go into a new iteration as <code>i</code> was declared in the <code>for</code> loop.</p>
  
  <p>But I'm not able to figure out why this value becomes 5 at the second <code>printf</code>.</p>