title: Why does Program fail after conclusion
body: <p>I am hoping someone can answer this and in effect teach me a little something. I have this simple little snippet of code and it works without error but then after the program ends Windows throws the following error </p>
  
  <blockquote>
    <p>program.exe has stopped working A problem caused the program to stop
    working correctly. Windows will close the program and notify you if a
    solution is available.</p>
  </blockquote>
  
  <p>With a button to Close Program</p>
  
  <p>The code in question below asks a user how many players there will be, then based on the number of players creates an array of a size equal to the number of players. Then a for loop prints each character name to the screen. Here is the code</p>
  
  <pre><code>int main()
      {
          int numplay;
          cout&lt;&lt;"How many players will there be? ";
          cin&gt;&gt; numplay;
          cin.ignore();
          cin.get();
          string *players = new string[numplay - 1]; 
          for (int x = 1; x &lt; numplay + 1; x++) {     
          string name;
          cout&lt;&lt;"What is Player "&lt;&lt; x &lt;&lt;"'s name? ";
          cin&gt;&gt; name;
          players[x - 1] = name;
          cin.ignore();
          }
          cin.clear();
          cin.sync();
          cin.get();
          for (int x = 0; x &lt; numplay; x++) {
          cout&lt;&lt; players[x] &lt;&lt;"\n";
          }
          delete[] players;
      }
  </code></pre>
  
  <p>The thing is like I said the code compiles and runs fine it's just at the end Windows throws the error mentioned above with few details. The problem is alleviated if you remove the -1 from the array declaration. However then that creates an extra unused array element. I hope this question is coherent it is one born completely from curiosity since Windows didn't give many details.</p>