121 Week 7 - 2D Arrays Flashcards
2D array
An array where each element in the array is another array.
Created in C by: datatype arrayName[int][int];
Indexing a 2D array
You can access individual elements in a 2D array using 2 sets of square brackets. The first for the “row” and the second for the “column”
e.g., arrayName[2][3]
Pros of 2D arrays
Can use a single name to represent multiple data items of the same type.
Random access so very fast to access an individual item.
Cons of 2D arrays
Arrays are fixed sizes
Insertion and deletion from arrays are costly
Constants
Similar to a variable but once it is defined, its value cannot be changed - it is kept constant. constant names are conventionally in uppercase.
#define CONST_NAME value
Benefits of constants
Can use the constant to represent a value which can be used throughout the code. If this value needs to be different, only change 1 line of code - the constant definition.