title: Variable created inside loop changes value during iterations in C
body: <p>I have code similar to the following in our product. According to me, the output is '0 1 2 3'. But the output of the similar code is '1 1 1 1'.</p>
  
  <pre><code>for(i = 0 ;i &lt; 5;i++){
      int j;
      if(i)
          printf("%d ",j);
      j = i;
  }
  </code></pre>
  
  <p>My understanding is that the j is allocated on the stack only once during the entire period of 'for' loop and the same value is used during iterations. Also, if I move the declaration of j outside for loop, I'm getting the expected result. What am I missing here?</p>
  
  <p>PS - When I run the same code on my personal machine, I am getting the expected output. But on production it is different.</p>