For dynamically sized arrays in C, your friend is the realloc() function. But instead of int a, you must use int *a = malloc(5 * sizeof(int));. Only then can you use the realloc() function to resize the array. In other words...
int *Array = (int *) malloc(3 * sizeof(int)); // Create an array with 3 ints
Array = 11;
Array = 250;
Array = 7;
// Now I want to increase its size...
Array = (int *) realloc(Array, 5 * sizeof(int)); // I've now reallocated the array to 5 ints
Array = 9;
Array = 999;
Reallocating should only be done when absolutely necessary. This is because there is a highly possible performance hit using this function as it needs to find a place in memory where the data can fit. In other words, if the array cannot grow in its place, realloc() will find a new place and copy the data to the new place. Doing this too much can be costly in clock cycles.
Just a small addition to the above post.
When ever you declare arrays dynamically you must
int *arr =(int *)malloc(sizeof(int)*10);
// Check if you did get the memory you asked for
printf("No memory. Terminating program\n");
printf("Sufficient memory found\n");
// Do operation on the array here
free(arr); // Free the memory that was given to you after you are done using it
public class GrossmontBank
//class variables (global - accessible throughout this class)
//scanner object to be used throughout
private static Scanner input = new Scanner(System.in);