title: False min and max assignments in function
body: <p>I have a function which is supposed to find min and max in an array using struct.
  But somehow the function assigns wrong values to min and max variables. Could someone please explain where do I have the mistake? Thank you very much. P.S. In my assignment the function doesn't need to take the first element of the array</p>
  <pre><code>min_max_t min_max(unsigned int *array, int size)
  {
      min_max_t flag;
      flag.min = array[1];
      flag.max = array[1];
      printf(&quot;Flag.min: %d | &quot;, flag.min);
      printf(&quot;Flag.max: %d\n&quot;, flag.max);
      for (int i = 1; i &lt; size; i++)
      {
          printf(&quot;i = %d - [A:%d - Min:%d - Max:%d]\n&quot;, i, array[i], flag.min, flag.max);
          if(array[i] &gt; flag.max)
          {
              flag.max = array[i];
          }
          else if (array[i] &lt; flag.min)
          {
              flag.min = array[i];
          }
          printf(&quot;i = %d - [A:%d - Min:%d - Max:%d]\n\n&quot;, i, array[i], flag.min, flag.max);
      }
      return flag;
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/PgL5K.png" rel="nofollow noreferrer">Screenshot of function process</a></p>