Arrays
by
, January 29th, 2012 at 05:01 PM (2479 Views)
Arrays are used to store many values under the one variable, so to speak. You can initialise an array the long and drawn out way by manually assigning each index a value or you can implement an array initialiser to do the job for you.
In this example, array1 is the slow way, and array2 makes use of an array initialiser. To build an array, you must first create the variable. You do this by typing the data type (int) followed by the array name (array1) and then add two square brackets ([]) to show that we're working with an array. Set this equal to a new int (if that is the chosen data type) followed by the number of indices in square brackets. That's the slow way of course.
You can use an array initialiser as follows. Data Type arrayName[] = {index1, index2, index3, etc};. That's a much easier was of going about building an array.