From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Working with multi-dimensional arrays

Working with multi-dimensional arrays - C Tutorial

From the course: Complete Guide to C Programming Foundations

Working with multi-dimensional arrays

- [Instructor] Most arrays are linear or one dimensional, but they can branch out into other dimensions as well. For example, in this code, you see a two-dimensional array. It works like a table with rows and columns. The grid array declaration can be read as a matrix of five rows of two columns, or five columns of two rows. The arrays elements must also be referenced by using the same dimensions. At lines 10 and 11, you see the two sets of brackets that refer to element X and elements zero and one. The same bracket pairs are used in line 15 as well. Run to see the table, and there it is. The multidimensional array in this code generates a three by three matrix. The character array tictactoe is two dimensional with three elements in each dimension, or three rows of three columns, essentially a grid or matrix. Nested loops fill the grid with period characters. A second set of nested loops outputs the grid. See how the elements are referenced at line 18? Variables x and y represent…

Contents