title: Why is int array not initialized to zeros in C++?
body: <p>I have a basic program in C++ which lists a given number of primes. The class which does the work is below - my question is, when the input for "amount" is 10 (specifically 10 - it works fine for all other numbers I've tried), the array that is generated just below is not initialized to an array of zeros. Hence, "the last element of the array is empty" returns false, and my code does not get to run properly.</p>
  
  <p>I don't know whether I've misunderstood, but shouldn't the int array initialize to zeros? If not, what is special about the integer 10 which causes it to initialize to strange values?</p>
  
  <pre><code>int* primecalc(int amount) {
  
  int* primes = new (nothrow) int [amount];
  
  //Throw an error if we can't allocated enough memory for the array.
  if (primes==0) {
  cout&lt;&lt; "Error allocating memory.";
  return 0;
  }
  
  //Otherwise, start iterating through the numbers.
  else {
  primes[0] = 2;
  primes[1] = 3;
  
  int p = 2;
  
  for (int i=4;primes[amount]==0;i++) {
  int j = 0;
  int k = 0;
  
      while ((primes[j]&lt;=floor(i/2)) &amp;&amp; !(primes[j]==0) &amp;&amp; (k==0)) {
  
          if ((i % primes[j]) == 0) {
          k=1;
          } 
      j++;
      } //end the while loop
  
  if (k==0) {
          primes[p] = i;
          p++;
  
  }
  
  } //end the for loop
  
  } //end the "else" part (this was only necessary in case memory could not be allocated)
  
  return primes;
  }
  </code></pre>
  
  <p>I also tried without (nothrow), with the same result. Thanks in advance for any help!</p>