WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Go - Multidimensional Arrays in Go


Go supports multidimensional arrays. The simplest form of a multidimensional array is the two-dimensional array.

var variable_name [SIZE1][SIZE2]...[SIZEN] variable_type

Two-Dimensional Arrays

A two-dimensional array is the simplest form of a multidimensional array. A two-dimensional array is, in essence, a list of one-dimensional arrays.
var arrayName [ x ][ y ] variable_type
Where variable_type can be any valid Go data type and arrayName will be a valid Go identifier. A two-dimensional array can be think as a table which will have x number of rows and y number of columns. A 2-dimensional array a, which contains three rows and four columns can be shown as below

Initializing Two-Dimensional Arrays

Multidimensional arrays may be initialized by specifying bracketed values for each row. Following is an array with 3 rows and each row has 4 columns.

a = [3][4]int{  
   {0, 1, 2, 3} ,   /*  initializers for row indexed by 0 */
   {4, 5, 6, 7} ,   /*  initializers for row indexed by 1 */
   {8, 9, 10, 11}   /*  initializers for row indexed by 2 */
}