Use dynamic memory allocation, if you don't know exactly how much memory your program will need to allocate at compile-time.
int a[n]
for example will limit your array size to n. Also, it allocated n x 4 bytes of memory whether you use it or not. This is allocated on the stack, and the variable n must be known at compile time.
int *a = (int *)malloc(n * sizeof (int))
on the other hand allocated at runtime, on the heap, and the n
needs to be known only at runtime, not necessarily at compile-time.
This also ensures you allocate exactly as much memory as you really need. However, as you allocated it at runtime, the cleaning up has to be done by you using free
.