Dynamic Memory Allocation
Suppose that we want to use an array to storage a series of input data but the program does not known the size of the array until the user gives some inputs.
(a) constant size array. This works if the input elements is less than 100, but wasteful if the input data is much less than 100.
(b) dynamic memory allocation. Ask the user to enter the array size n, allocate exactly n cells of type int.
int n, *a;
scanf("%d", &n);
a = malloc( n*sizeof(int) );