Expand array

is it possible to add new elements to a array?without using vector?

arrays are fixed sized.
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).
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
Topic archived. No new replies allowed.