title: C++ float array initialization
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/10828294/c-and-c-partial-initialization-of-automatic-structure">C and C++ : Partial initialization of automatic structure</a>  </p>
  </blockquote>
  
  
  
  <p>While reading <a href="https://rads.stackoverflow.com/amzn/click/com/0735619670" rel="noreferrer" rel="nofollow noreferrer">Code Complete</a>, I came across an C++ array initialization example:</p>
  
  
  
  <pre><code>float studentGrades[ MAX_STUDENTS ] = { 0.0 };
  </code></pre>
  
  <p>I did not know C++ could initialize the entire array, so I've tested it:</p>
  
  
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      const int MAX_STUDENTS=4;
      float studentGrades[ MAX_STUDENTS ] = { 0.0 };
      for (int i=0; i&lt;MAX_STUDENTS; i++) {
          cout &lt;&lt; i &lt;&lt; " " &lt;&lt; studentGrades[i] &lt;&lt; '\n';
      }
      return 0;
  }
  </code></pre>
  
  <p>The program gave the expected results:</p>
  
  <pre><code>0 0
  1 0
  2 0
  3 0
  </code></pre>
  
  <p>But changing the initialization value from <code>0.0</code> to, say, <code>9.9</code>:</p>
  
  <pre><code>float studentGrades[ MAX_STUDENTS ] = { 9.9 };
  </code></pre>
  
  <p>Gave the interesting result:</p>
  
  <pre><code>0 9.9
  1 0
  2 0
  3 0
  </code></pre>
  
  <p>Does the initialization declaration set only the first element in the array?</p>