From the course: C Programming Basics: Flow Control, Variables, and Pointers

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Creating multidimensional arrays

Creating multidimensional arrays

- [Instructor] An array is like a line of variables all marching in a row, but not all data prefers a single line. Sometimes you must deal with a grid. In that case, you enter into the realm of the multi-dimensional array. So think of a grid. You have rows and columns. In this code, a two dimensional integer array is declared at line five. Two sets of square brackets are used. One for each dimension in the array. Lines nine through 10 are nested for loops to fill each array element with a value zero. This initializes the array. This step is important because using an array element variable without initializing it can lead to unpredictable results. Say this grid represents a game of tic-tac-toe or knots and crosses. The statement at line 13 sets a value in the middle square. The final set of nested for loops displays the entire grid. Build and run. You see that the one is placed in the lower right corner of the…

Contents