Using Multidimensional Arrays

The power of an array can be greatly increased by creating multidimensional arrays: an array whose element values are also arrays. This concept is tough to visualize (it's roughly equivalent to a stack of two-column tables) but not that hard to use.

All of the same rules for arrays apply to multidimensional arrays. Once again you'll use the square brackets to indicate the number of elements. This time you'll do so twice:

float grades[3][20];

The first number indicates the number of subarrays (or tables, in layman's terms) the main array contains. The second number specifies the number of rows each subarray (table) contains.

Populating multidimensional arrays is also tricky. You first refer to the subarray index ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.