[Solved] How to grow a pointer or an array in C at runtime (without knowing the end length at compile time)


OP’s mostly has it.

It is just printing the first element each time.

    // printf("%d", *arr);
    printf("%d", arr[n-1]);

is it possible to do it with an array?

No. In C an array cannot change size once it is defined.

The memory size allocated and referenced by a pointer can change though.

solved How to grow a pointer or an array in C at runtime (without knowing the end length at compile time)