size *= 2; arr = realloc(arr, size * sizeof(int)); if (arr == NULL) { fprintf(stderr, "Not enough memory\n"); exit(EXIT_FAILURE); }