- 1
How to resize dynamic array?
2 Respuestas
0
Arrays have fixed sizes, static or dynamic doesn't matter. You can use various methods instead of trying to resize an array:
You can declare another larger array and dispose off the earlier one after copying it's values.
Another option is to use vector in C++.
PS: If you have to resize a lot, use a Linked List instead.
0
Pointer arrays:
int *x;
x = (int *) malloc(nr_of_ints * sizeof(int));
x = (int *) realloc(x, new_size * sizeof(int));
free(x);