1 / 5

Two-Dimensional Arrays

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.

obelia
Download Presentation

Two-Dimensional Arrays

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Two-Dimensional Arrays Robert Reaves

  2. 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!

  3. Array Declaration • DataTypeArrayName [ ConstIntExpression ] [ ConstIntExpression ]; • Example: • constint NUM_ROWS = 100; • constint NUM_COLS = 9; • float alpha [NUM_ROWS][NUM_COLS];

  4. 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;

More Related