Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int* my_array = malloc(10 * sizeof(int));
- int n_used_elements = 0; // Need to keep track of the used elements and the size
- int my_array_size = 10; // reserved size
- int myArray[10];
- int* myArray = malloc(10, sizeof(int));
- typedef struct {
- int *array;
- size_t used;
- size_t size;
- } Array;
- void insertArray(Array *a, int element) {
- if (a->used == a->size) {
- a->size *= 2; // double the size when exceeding the size of the array
- a->array = (int *)realloc(a->array, a->size * sizeof(int));
- }
- a->array[a->used++] = element;
- }
Advertisement
Add Comment
Please, Sign In to add comment