storage style behind c++ vector implementation
<pre><code>vector &lt;int&gt; x = {1,2,3};
vector &lt;int&gt; y = {4,5,6};
</code></pre>

<p>With a bit of simplification on the code, I have two vector variable representing above array of values.
I was working on something and learned that when I do </p>

<pre><code>cout &lt;&lt; x[-1] &lt;&lt; endl;
</code></pre>

<p>it output will be </p>

<pre><code>6
</code></pre>

<p>Based on the above experiment, the vector data structure stores data like this,</p>

<pre><code>{4,5,6,1,2,3}
</code></pre>

<p>However, I do not think this is very safe, as one vector variable can access other vector variable, which can make unexpected error for amateur programmer like me.</p>

<p>I want to know if my above statement is valid, or I am misunderstanding something. I thought that having index variables unsigned can solve this issue, but I still want to know that I am understanding the visual structure clearly.</p>

<p>I have read something about unpredictability in assignment, so that can be the case as well. </p>

<p>Can someone help me clear this out?</p>

<p>Thank you very much.</p>