Home  >  Article  >  Backend Development  >  How to define a two-dimensional array in golang

How to define a two-dimensional array in golang

尚
Original
2020-03-27 14:30:0612472browse

How to define a two-dimensional array in golang

Go language supports multi-dimensional arrays. The following is the commonly used multi-dimensional array declaration method:

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

Two-dimensional array

二A two-dimensional array is the simplest multi-dimensional array. A two-dimensional array is essentially composed of a one-dimensional array. The two-dimensional array is defined as follows:

var arrayName [ x ][ y ] variable_type

variable_type is the data type of the Go language, arrayName is the array name, and the two-dimensional array can be considered as a table, x is the row, and y is the column.

Initializing a two-dimensional array

Multi-dimensional arrays can be initialized through braces. The following example is a two-dimensional array with 3 rows and 4 columns:

a = [3][4]int{  
 {0, 1, 2, 3} ,   /*  第一行索引为 0 */
 {4, 5, 6, 7} ,   /*  第二行索引为 1 */
 {8, 9, 10, 11},   /* 第三行索引为 2 */
 }

For more golang knowledge, please pay attention to the golang tutorial column on the PHP Chinese website.

The above is the detailed content of How to define a two-dimensional array in golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn