title: change of vectors first pointer
body: <p>When i use vector to store some data, I usually access to this data by the pointer of the vector's first entry. because it it faster than the at() method. But I realize that when I insert a block of data, say an array to the end of vector, the first entry's pointer changes. This may be realated to stack stuff, But if I add the array one element at a time by push_back, first pointer does not change. So why is that? Should i worry about using a pointer to access the elements? </p>
  
  <p>Here is a sample code for those who wants to check out:</p>
  
  <pre><code>int arrayLen = 500000;
   vector&lt;int&gt; vint = vector&lt;int&gt;(2000,0);
   int * firstEntry = &amp;vint[0];
  
   int * iarray = new int[arrayLen];
   for(int i = 0; i&lt; arrayLen; i++)
   {
    iarray[i] = i;
   }
   vint.insert(vint.end(),iarray,iarray+arrayLen);
   cout &lt;&lt; firstEntry &lt;&lt; "," &lt;&lt; &amp;vint[0] &lt;&lt; endl; // They ar not equal;
  
           // reset the vector
   vint.clear();
   vint.resize(2000,0);
   firstEntry = &amp;vint[0];
  
   for(int i = 0; i&lt; arrayLen; i++)
   {
    vint.push_back(iarray[i]);
    if(firstEntry != &amp;vint[0])
     cout &lt;&lt; firstEntry &lt;&lt; "," &lt;&lt; &amp;vint[0] &lt;&lt;","&lt;&lt; i &lt;&lt; endl;
   }// nothing  is written
  
   cout &lt;&lt; firstEntry &lt;&lt; "," &lt;&lt; &amp;vint[0] &lt;&lt; endl; // now they are equal;
  </code></pre>