Symantec Interview Question
Software Engineer / DevelopersSTL Vectors have been implemented as dynamic arrays. A dynamic array is capable of reallocating its underlying buffer as soon as its current capacity has exhausted (i.e. an attempt is made to insert n+1th element while the current capacity is only n).
In case of default constructor : No memory is allocated.
In case of constructor vector avec(10), where the capacity is given by the argument, allocate array of size 10 on heap. (there must be a default constructor for this for the given object type).
When the vector need to expand, it first allocate memory that is double of current capacity.
Now it copies all its current elements in the newly allocated array.
then it destroys the old arrays (delete []).
dynamic array
- dawninghu July 24, 2012