- 1

How to resize dynamic array?

4th Apr 2019, 2:16 PM
MUHAMMAD AHMAR ABEED KHAN
MUHAMMAD AHMAR ABEED KHAN - avatar
2 Antworten
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.
4th Apr 2019, 3:01 PM
Deepesh Choudhary
Deepesh Choudhary - avatar
0
Pointer arrays: int *x; x = (int *) malloc(nr_of_ints * sizeof(int)); x = (int *) realloc(x, new_size * sizeof(int)); free(x);
4th Apr 2019, 4:22 PM
Vlad Serbu
Vlad Serbu - avatar