Question regarding pointers and vectors

Jun 6, 2013 at 6:33am
[spoiler] NOOB here [/spoiler]

I am trying to learn pointers, I had a question in regards to how pointers 'point' with vectors, or I think that is my question.

for example lets say I have something like this

1
2
3
4
5
6
     
vector<string> question;
question.push_back("help");
question.push_back("me");

vector<string>* thanks = &question;  //pointer 


So here I made a pointer that points to the address of the array of
the vector question

if I wanted to see this address all I would simply have to do is this
 
cout << thanks << endl;


but if I wanted to see the address of a certain element in the vector I
am required to do this

 
cout << &((*thanks)[0]) endl;


and really I just want to know what is?

Why can I not just do it like this
 
cout << (thanks)[0] << endl;


to me, this would be asking for the
address at index 0. It seems like I would not have to
look at the object itself before pulling the address.


Any help would be great!







Jun 6, 2013 at 6:38am
I may have figured it out but correct me if I am wrong.

Calling the pointer to the vector says to look where the vector itself is, but using

 
cout << &((*thanks)[0]) endl;


tells the pointer thanks to look at the vector itself, then look at index zero in the vector and then pull the address of that element???

Seems like that sounds correct

Thanks again
Topic archived. No new replies allowed.