title: Same code produces different output depending on if curly braces are present
body: <p>I have this code:</p>
  
  <pre><code>int main() {
  
  int list[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  int max = 0, min = 0, small, large;
  
  for (int j = 0; j &lt; 10; ++j) {
  
      if(list[max] &lt; list[j]) {
          max = j;
          large = list[max];
      }
  
      if(list[min] &gt; list[j]) {
          min = j;
          small = list[min];
      }
  
      cout &lt;&lt; "Maximum :" &lt;&lt; large &lt;&lt; endl;
      cout &lt;&lt; "Minimum :" &lt;&lt; small &lt;&lt; endl &lt;&lt; endl;
  }
  </code></pre>
  
  <p>the <code>small</code> will not be correct in the above code.</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Maximum :-1482404720
  Minimum :0
  
  Maximum :2
  Minimum :0
  
  Maximum :3
  Minimum :0
  
  Maximum :4
  Minimum :0
  
  Maximum :5
  Minimum :0
  
  Maximum :6
  Minimum :0
  
  Maximum :7
  Minimum :0
  
  Maximum :8
  Minimum :0
  
  Maximum :9
  Minimum :0
  
  Maximum :10
  Minimum :0
  </code></pre>
  
  <p>However, the same code with the curly braces omitted like this, will work:</p>
  
  <pre><code>    if(list[max] &lt; list[j]) 
          max = j;
          large = list[max];
  
  
      if(list[min] &gt; list[j]) 
          min = j;
          small = list[min];
  </code></pre>
  
  <p>the above code now properly displays the minimum and maximum values.</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Maximum :1
  Minimum :1
  
  Maximum :2
  Minimum :1
  
  Maximum :3
  Minimum :1
  
  Maximum :4
  Minimum :1
  
  Maximum :5
  Minimum :1
  
  Maximum :6
  Minimum :1
  
  Maximum :7
  Minimum :1
  
  Maximum :8
  Minimum :1
  
  Maximum :9
  Minimum :1
  
  Maximum :10
  Minimum :1
  </code></pre>
  
  <p>Why is this happening? I've asked my lecturer and she doesn't know either, so I decided to ask here instead.</p>