title: Why does std::accumulate behave like this with standard arrays?
body: <p>I'm just getting into C++ and I think I have a handle on pointers, but <code>std::accumulate()</code> has me confused.</p>
  
  <p>Given the array:</p>
  
  <pre><code>int a[3] = { 5, 6, 7 };
  </code></pre>
  
  <p>I'd like to sum the values of the array with <code>std::accumulate()</code>, so I pass it a pointer to the first element, then the last, then the starting value of the accumulator.</p>
  
  <pre><code>std::accumulate(a, a + 2, 0);
  std::accumulate(&amp;a[0], &amp;a[2], 0);
  </code></pre>
  
  <p>Oops: either of these returns the sum of only the first two elements: <code>11</code>.</p>
  
  <p>On the other hand, if the second argument is a nonsensical pointer, just out of bounds...</p>
  
  <pre><code>std::accumulate(a, a + 3, 0);
  std::accumulate(&amp;a[0], &amp;a[3], 0);
  </code></pre>
  
  <p>... the correct value of <code>18</code> is returned.</p>
  
  <p>Could someone please explain this? I realise that I could avoid using simple arrays, but that's beside the point.</p>