Learn how to work with arrays that are structured as a table or grid with rows and columns.
A two-dimensional (2D) array in C is an extension of a 1D array, best visualized as a grid or a table with rows and columns. It is essentially an 'array of arrays'. A 2D array is used to store data that is naturally tabular, such as a tic-tac-toe board, a matrix in mathematical computations, or a spreadsheet. To declare a 2D array, you need to specify the data type, the array name, and two size values in separate square brackets: one for the number of rows and one for the number of columns. For example, `int matrix[3][4];` declares a 2D integer array named `matrix` with 3 rows and 4 columns, capable of holding a total of 3 * 4 = 12 integer elements. Accessing an element in a 2D array requires two indices: the row index and the column index, both of which are zero-based. For instance, `matrix[1][2]` refers to the element in the second row (index 1) and the third column (index 2). To process all elements in a 2D array, you typically use nested `for` loops. The outer loop iterates through the rows, and the inner loop iterates through the columns of each row. Initialization of a 2D array can be done at declaration by providing a nested list of values, where each inner list corresponds to a row. For example: `int arr[2][3] = {{1, 2, 3}, {4, 5, 6}};`. This initializes the first row with 1, 2, 3 and the second row with 4, 5, 6.