vector <int> x = {1,2,3};
vector <int> y = {4,5,6};
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
cout << x[-1] << endl;
it output will be
6
Based on the above experiment, the vector data structure stores data like this,
{4,5,6,1,2,3}
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.
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.
I have read something about unpredictability in assignment, so that can be the case as well.
Can someone help me clear this out?
Thank you very much.