Lecture 22 Objectives
At the end of today's class you should
KNOW:
- That C supports multi-dimensional arrays (arrays of arrays)
- That for-loops are frequently used to process arrays
- That arrays are stored in row-major order in C
- That programs can be made to run more efficiently by exploiting locality
- That when a two-dimensional array is passed as a parameter, the number of
columns must also be passed to ensure that C can calculate
the address of each array element
BE ABLE TO:
- Write C code to process each element of a two-dimensional array
- Define spatial locality and temporal locality
- Write code that accesses elements of an array so that it
exploits spatial locality and temporal locality
Sample Exam Question:
Rewrite the loop in the following code so that it access the array list
using
pointer notation instead of using square-bracket notation:
int list[5][10], i;
int *pList;
pList = list;
// set the 0th element of each row to i
for (i=0; i<5; i++)
list[i][0] = i;