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

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

王林
Release: 2020-12-24 17:07:47
Original
10390 people have browsed it

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
Copy after login

2. Use automatic type deduction to create an array

Definition: array name: = [number of elements] data type

arr:=[10]int
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template