Home>Article>Backend Development> What are the methods to define an array in Go language?

What are the methods to define an array in Go language?

王林
王林 Original
2020-12-17 11:44:57 10309browse

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].

What are the methods to define an array in Go language?

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!

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