@MikeCAT strictly speaking, this is incorrect. For array of integers, OP can use `malloc` to allocate initial array, and than use `realloc` in attempt to increase allocated area.
– SergeyAMay 18 '21 at 17:23
@SergeyA What MikeCAT said is correct for C++'s `new[]`. And you can't mix C's `malloc()`/`realloc()` with C++'s `delete[]`, either. You would have to use C's `free()` instead. In any case, `realloc()` will do a new allocate+copy if it can't expand the array in-place.
– Remy LebeauMay 18 '21 at 17:26
@SergeyA Be careful when using `malloc()` in C++. It may not work with complicated classes like `std::string` because it doesn't do required initialization by default.
– MikeCATMay 18 '21 at 17:27
@MikeCAT "*[malloc] doesn't do required initialization by default*" - more accurately, replace "by default" with "at all".
– Remy LebeauMay 18 '21 at 17:28
@RemyLebeau I am well aware of non-mixable allocations. But I said so explicitly: `use malloc to allocate initial array,`.
– SergeyAMay 18 '21 at 17:45
@MikeCAT I am well aware of this as well. This is why I highlighted the fact that OP is using array if `int`s.
– SergeyAMay 18 '21 at 17:45