Pointers and Arrays
Pointers and Arrays
5 6 1
7 8
Multi-dimensional arrays Summary
• Remember that memory is a sequence of bytes.
• The name of an array can also be used
row 0 row 1 row 2 as a pointer to the zero’th element of the
0 1 2 3 4 5 6 7 8
array.
int a[3][3] = { {0, 1, 2}, • This is useful when passing arrays as
{3, 4, 5}, parameters.
{6, 7, 8}};
• Arrays in C are stored in row-major order • Use array notation rather than pointer
• row-major access formula arithmetic whenever you have an array.
x[i][j] == *(x + i * n + j) But use array
where n is the row size of x notation! 9 10