61 likes | 238 Views
Two-Dimensional Arrays. Robert Reaves. Two-Dimensional Array. Used to represent items in a table with rows and columns, of the same data type. Good for representing board games, where the screen is though of as a two-dimensional array.
E N D
Two-Dimensional Arrays Robert Reaves
Two-Dimensional Array • Used to represent items in a table with rows and columns, of the same data type. • Good for representing board games, where the screen is though of as a two-dimensional array. • A component in a two-dimensional array is accessed by specifying the row and column indexes of the item. • Think of a map!
Array Declaration • DataTypeArrayName [ ConstIntExpression ] [ ConstIntExpression ]; • Example: • constint NUM_ROWS = 100; • constint NUM_COLS = 9; • float alpha [NUM_ROWS][NUM_COLS];
Array Access • To access an individual component of an array, two expressions are used to specify its position. • Array Component Access • ArrayName [ IndexExpression ] [ IndexExpression ]; • Example: • alpha[0][5] = 36.4;