 <p>When doing your comparison, <code>&lt;= size</code> means you're iterating 1 past the end of the array. It's most likely picking up some really huge garbage value and that becomes the minimum.</p> <p>Use <code>for (int i = 1; i &lt; size; ++i) { /* ... */ }</code> to get what you need.</p>