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
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.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
Why not? standard guarantees that.
&vec is not the same as &vec[0].
--
Ian Collins.
Where?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Opps, I misread Pet's comment.
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.)
Sigh. Communication always relies on assumptions. It's always possible
to make different assumptions and come to different results. The only
issue is whether those other assumptions are reasonable given the
context. Since he didn't say what vector he was talking about, it's
reasonable to assume that it's std::vector.
>
> (Yes, just nitpicking.)
No, just wasting bandwidth playing gotcha.