0

Why base address of vector is not modified

Hi Pleaae refer xode below : I have tried push back to vector so that re allocation happen internally for vector. As size and capacity changed , it seems it does so. Now question is about base address of vector... why it is still same ? Does it gurantee the same address ? I thought it should give diff address for vector as re allocation happend. https://code.sololearn.com/ceoWGtZ18sP1/?ref=app

6th Nov 2022, 7:33 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Réponses
+ 3
"&v" would give you the memory address of an object of type vector and not the underlying array the class is operating upon. If you check the base address of the underlying data structure ( &v[0] ), you can see it does indeed relocate as soon as the vector class dynamically reallocates the memory. https://code.sololearn.com/cZAEc61hNHh8/?ref=app
7th Nov 2022, 1:17 AM
Arsenic
Arsenic - avatar
+ 3
Thanks
7th Nov 2022, 2:39 AM
Ketan Lalcheta
Ketan Lalcheta - avatar