Home >Backend Development >Golang >What are the methods to define an array in Go language?
The methods for defining an array in Go language include: 1. Traditional method, such as [var arr [8]int=[8]int]; 2. Automatic type derivation, such as [arr:=[10]int ]; 3. [Array name:=[...]data type], such as [arr:=[...]int].
The environment of this article: Windows 10 system, Go 1.11.2 version, this article is applicable to all brands of computers.
(Learning video sharing: Programming video)
Detailed introduction:
1. Use the traditional way to define arrays:
Definition :var array name [number of elements] data type
var arr [8]int=[8]int
2. Use automatic type deduction to create an array
Definition: array name: = [number of elements] data type
arr:=[10]int
3. Using three-point automatic type derivation, you can create an array based on the number of elements. The length of the array can be changed at will.
Definition: Array name: =[...]data type
arr:=[...]int
Related recommendations: golang tutorial
The above is the detailed content of What are the methods to define an array in Go language?. For more information, please follow other related articles on the PHP Chinese website!