title: std::vector segmentation fault with and without initialization
body: <p>I was doing some experimentation with vectors in C++. The code I'm using is the following</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
     std::vector&lt;float&gt; aVector = std::vector&lt;float&gt;(10);  // IMPORTANT LINE
     std::cout &lt;&lt; "Vector size: " &lt;&lt; aVector.size() &lt;&lt; std::endl;
     aVector.clear();
     aVector[0] = 2.2;
     std::cout &lt;&lt; "Vector size: " &lt;&lt; aVector.size() &lt;&lt; std::endl;
     aVector.push_back(0.1);
     std::cout &lt;&lt; "Vector size: " &lt;&lt; aVector.size() &lt;&lt; std::endl;
     aVector.clear();
     std::cout &lt;&lt; "Vector size: " &lt;&lt; aVector.size() &lt;&lt; std::endl;
     aVector[0] = 2.1;
     std::cout &lt;&lt; "Vector size: " &lt;&lt; aVector.size() &lt;&lt; std::endl;
  
     return 0;
  }
  </code></pre>
  
  <p>If I have the vector, initialize it with N elements and then clear the vector and try to put assign value <code>aVector[0] = 1.1</code> the program goes all the way to the end with no segmentation faults.</p>
  
  <p>On the other hand if I create a vector but don't pass the number of initial elements, when trying to assign the value with <code>aVector[0] = 1.1</code> it will crash the program.</p>
  
  <p>The only way a segmentation fault can arise is because I'm trying to write to an invalid memory address. So, to my understanding, creating the vector and not initializing means that the pointer to the actual vector data points to nowhere while initializing the vector and clearing keeps a pointer to an allocated memory but the size of the vector only shrinks to 0? does it mean that even after clearing a vector the values previously stored are still there?</p>
  
  <p>Is this the behavior defined in the specification? I would've expected that clear erases and frees the memory previously allocated.</p>