Если вы ищете динамический массив в C, он довольно прост.
1) Объявить указатель для отслеживания памяти,
2) Выделите память,
3) Используйте память,
4) Освободите память.
int *ary; //declare the array pointer
int size = 20; //lets make it a size of 20 (20 slots)
//allocate the memory for the array
ary = (int*)calloc(size, sizeof(int));
//use the array
ary[0] = 5;
ary[1] = 10;
//...etc..
ary[19] = 500;
//free the memory associated with the dynamic array
free(ary);
//and you can re allocate some more memory and do it again
//maybe this time double the size?
ary = (int*)calloc(size * 2, sizeof(int));
Информация о calloc()
может быть найдена здесь , то же самое можно сделать с помощью malloc()
, вместо этого используя malloc(size * sizeof(int));