Erin's CS stuff

CS stuff!

2D Arrays Quick Guide

Application Example Notes
A declaration statement creates a composite variable to store a group of values with multiple dimensions. declaration
  • needs a data type, indentifier, and two sizes between square brackets
  • the sizes between the square brackets must be of type int
  • the first size is the number of rows
  • the second size is the number of columns
  • best practices include using macros for the sizes
A single array element is used for individual array values. element
  • needs a indentifier and two indexes between square brackets
  • the indexes between the square brackets must be of type int
  • the first index is for the row number (starting at 0)
  • the second index is for the column number (starting at 0)
  • this expression should NOT include a data type
all array elements must be accessed one at a time elements
  • needs nested for loops to repeat accessing each element
  • the outer loop is generally for the controlling the row index
  • the inner loop is generally for the controlling the column index
  • the indexes will usually start at 0 and continue until size - 1
NOTE: 2D Arrays can also use int variables as the sizes during declaration.
NOTE: 2D Arrays can also have arbitrarily large sizes for any dimension for which we can't determine the number of objects before storing them in the array.