Multidimensional arrays syntax

Multidimensional arrays are created by specifying two or more pairs of square brackets in the declaration. Multi-dimensional arrays are created as arrays of arrays. The initialization takes place in the same way as one-dimensional arrays by specifying the number of elements per dimension. Multi-dimensional arrays can be accessed by specifying all required indices, each in their own square brackets. Even with multi-dimensional arrays, a literal initialization can be achieved by nesting the initialization sequences.

// Declare a 2D array of integers with 3 rows and 4 columns
int myArray[3][4];

// Initialize a 2D array of integers with 3 rows and 4 columns
int myArray[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};

// Access an element in the 2D array
int x = myArray[1][2]; // gets the element in the second row (index 1) and third column (index 2)

// Change an element in the 2D array
myArray[2][1] = 13; // changes the element in the third row (index 2) and second column (index 1) to 13