Suppose I set an array like this:
int *p,q; ///q мне предварительно известно p=new int q; So, how can I increase the number of elements in the array if necessary?
If you do not want to use the native C ++ STL vector<int> , then instead of new/delete you can use absolutely POSIX malc malloc/realloc/free from libc.
Actually, you can get by with one realloc(ptr, size) , skillfully controlling the values of ptr and size .
See man 3 realloc .
No Only by creating a new dynamic array and copying the old one there.
In real projects in such cases, in order to allocate memory each time, allocate it with a margin.
Source: https://ru.stackoverflow.com/questions/250299/
All Articles
std::vector<int>? And if you need to be able to change and work with pointers, then realloc. - KoVadim