(&vec)== &vec[0]?

I

Ioannis Vranos

C++03:


Is it always guaranteed that in vector:


vector<int> vec(10);

&vec always points to the first element of the array, for vec.size()> 0?
 
S

shaun roe

Ioannis Vranos said:
C++03:


Is it always guaranteed that in vector:


vector<int> vec(10);

&vec always points to the first element of the array, for vec.size()> 0?

no
 
J

Juha Nieminen

Pete said:
C++03:


Is it always guaranteed that in vector:


vector<int> vec(10);

&vec always points to the first element of the array, for vec.size()> 0?

No. In fact, it's almost certainly not true. vector dynamically
allocates memory for its stored objects, so &vec[0] has no inherent
relationship to &vec.

Since we don't know what "vector" he is talking about (since he didn't
say he is talking specifically about std::vector), it could
theoretically be possible for this to be some kind of user-defined
vector class for which &vec and &vec[0] are the same thing.

(Yes, just nitpicking.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top