title: vector::clear in C++
body: <p>I have some difficulties in understanding the behaviour of the C++ clear function, when applied to a vector.</p>
  
  <p>I tried to compile and run the following function:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  int main ()
  {
    unsigned int i;
    vector&lt;int&gt; myvector;
    myvector.push_back (1);
    myvector.push_back (2);
    myvector.push_back (3);
  
    cout &lt;&lt; "myvector contains:";
    for (i=0; i&lt;myvector.size(); i++) cout &lt;&lt; " " &lt;&lt; myvector[i];
  
    myvector.clear();
    myvector.push_back (11);
    myvector.push_back (12);
  
    cout &lt;&lt; "\nmyvector contains:";
    for (i=0; i&lt;myvector.size(); i++) cout &lt;&lt; " " &lt;&lt; myvector[i];
    cout &lt;&lt; endl;
  
    cout &lt;&lt; " entry3 = " &lt;&lt; myvector[2]&lt;&lt;endl;
  
    return 0;
  }
  </code></pre>
  
  <p>And this is the output:</p>
  
  <pre><code>myvector contains: 1 2 3
  myvector contains: 11 12
  entry3 = 3
  </code></pre>
  
  <p>How is it possible that the information of the third entry of the vector has not been erased when clearing the vector?</p>