Expand array

Oct 3, 2014 at 8:47am
is it possible to add new elements to a array?without using vector?

Oct 3, 2014 at 9:50am
arrays are fixed sized.
Oct 3, 2014 at 10:10am
Statically allocated arrays are fixed sized.

Dynamically allocated arrays ... you can allocate another, larger, array on the fly, copy existing values from the old array to the new one, set the new elements, deallocate original array and make sure that anyone using the array points to the new one (and knows current size).
Oct 3, 2014 at 10:23am
1
2
3
4
5
6
7
8
int *pt = new int [10];
// ...
delete[] pt;
int *pt = new int [10]; //actually this pt is new pt > not the previous pt, although same size
// no way to "push_back()" to this pt
//i am saying about "this pt" and "that pt"
// ...
delete[] pt;
Last edited on Oct 3, 2014 at 10:25am
Topic archived. No new replies allowed.