golang tutorial - Golang Multidimensional Array | Go multidimensional arrays - golang - go programming language - google go - go language - go program - google language
golang , gopro , google go , golang tutorial , google language , go language , go programming language
Two Dimensional declaration
- Go programming language supports multidimensional arrays. Here is the general form of a multidimensional array declaration
- For example, the following declaration creates a three dimensional 4,3,2 integer array:
Arrays Two-Dimensional structure
- The simplest form of the multidimensional array is the two-dimensional array.
- To declare a two-dimensional integer array of size x,y. Below is the syntax,
- Where variable_type can be any valid Go data type
- 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 which is shown below
- Every element in array a is identified by an element name of the form a[ i ][ j ]
- where a is the name of the array, and i and j are the subscripts that uniquely identify each element in a.
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.
- Another way of initializing Multidimensional ( Two dimensional ) arrays
Accessing Two-Dimensional Array Elements
- An element in 2-dimensional array is accessed by using the subscripts, i.e., row index and column index of the array.
- The above statement will take 4th element from the 3rd row of the array. You can verify it in the above diagram.
- Let us check below program where we have used nested loop to handle a two dimensional array: