title: Why is an incremental increase to an integer in C causing overflow?
body: <p>I'm working through CS50 and am currently working on a small function to determine the winner(s) of an election.</p>
  <pre><code>  void print_winner(void)
      {
          int max_votes = 0;
          int num_of_winners = 0;
          string winners [] = {};
      
          for (int i = 0; i &lt; candidate_count; i++) {
          //Determine if the candidate has enough votes to be considered a winner
              if (candidates[i].votes &gt;= max_votes) {
                  //If so, increment the number of winners
                  num_of_winners ++;
                  //Assign the winning candidate to the winners array
                  winners[i] = candidates[i].name;
                  //And reset the max number of votes required to now be considered a winner
                  max_votes = candidates[i].votes;
              }
             printf(&quot;number of winners  %i\n&quot;, num_of_winners);
          }
      
      for (int i = 0; i &lt; num_of_winners; i++) {
           printf(&quot;winner  %s\n&quot;, winners[i]);
      }
          return;
      }
  </code></pre>
  <p>Whenever I run the function the counter seems to increment properly but on the last printout the  number is clearly wrong:</p>
  <p><a href="https://i.stack.imgur.com/qnXVG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qnXVG.png" alt="Console print out" /></a></p>
  <p>I'm still learning C and from what I've read this sounds like either a memory allocation issue or some kind of integer overflow issue however I'm unsure what the issue is and how to fix it.</p>