当前位置:网站首页>[Yugong series] go teaching course in July 2022, an array of 020 go containers
[Yugong series] go teaching course in July 2022, an array of 020 go containers
2022-07-29 00:50:00 【Yugong move code】
List of articles
One 、Go Array of containers
1. What is an array
Array (Array) Is an ordered sequence of elements . If you name a limited set of variables of the same type , So the name is array name . The variables that make up an array are called the components of the array , Also known as an array of elements , Sometimes called subscript variable . The number used to distinguish the elements of an array is called the subscript . Arrays are in programming , For convenience , A form in which elements of the same type are organized in an orderly manner . These ordered sets of data elements of the same kind are called arrays .– Baidu Encyclopedia
An array is a continuous area of memory of a fixed length .
2.Go Array in language
stay Go Once the language array is declared , The size of the array is determined , You can't change the size, but you can change the array members .
Go The format of language defined array is as follows :
var Array variable name [ Element quantity ]T
explain :
- Array variable name : Define the variable name of an array
- Element quantity : Define the size of the array
- T Can be any basic type , It can even be the array itself , If it's an array , You can implement multidimensional arrays
Related cases :
package main
import (
"fmt"
)
func main() {
// Define a variable as arr, The member type is string, The size is 3 Array of
var arr [3]string
// Assignment operation
arr[0] = " Foolish Old Man 1 Number "
arr[1] = " Foolish Old Man 2 Number "
arr[2] = " Foolish Old Man 3 Number "
fmt.Println(arr)
}

3. Initialize array
package main
import (
"fmt"
)
func main() {
// Define a variable as arr, The member type is string, The size is 3 Array of
var arr = [3]string{
" Foolish Old Man 1 Number ", "q Foolish Old Man 2 Number ", " Foolish Old Man 3 Number "}
fmt.Println(arr)
}

4. Traversal of array
package main
import (
"fmt"
)
func main() {
// Define a variable as arr, The member type is string, The size is 3 Array of
var arr = [...]string{
" Foolish Old Man 1 Number ", "q Foolish Old Man 2 Number ", " Foolish Old Man 3 Number "}
for index, v := range arr {
fmt.Printf("index: %d, value: %s\n", index, v)
}
}

边栏推荐
- 会议OA项目之会议通知&会议反馈&反馈详情功能
- andriod6.0低功耗模式(关闭wifi、蓝牙、gps、屏幕亮度等)
- PTA (daily question) 7-73 turning triangle
- Dynamic programming (V)
- [ESN] learning echo state network
- AQS原理
- SAP vl02n delivery note posting function WS_ DELIVERY_ UPDATE
- Longest ascending subsequence
- Android必备的面试技能(含面试题和学习资料)
- Depth first search (DFS) and its matlab code
猜你喜欢
![[basic course of flight control development 8] crazy shell · open source formation uav-i2c (laser ranging)](/img/0b/d6defd524f83e69b40b5878ffe2e3c.png)
[basic course of flight control development 8] crazy shell · open source formation uav-i2c (laser ranging)

【开发教程10】疯壳·开源蓝牙心率防水运动手环-蓝牙 BLE 收发

Data warehouse construction - ads floor

云函数实现网站自动化签到配置详解【Web函数/Nodejs/cookie】

【飞控开发基础教程8】疯壳·开源编队无人机-I2C(激光测距)

数仓搭建——DWT层

【开发教程11】疯壳·开源蓝牙心率防水运动手环-整机功能代码讲解

Download the latest version of visual studio code and connect to the server remotely (very detailed)

MySQL sub database and sub table and its smooth expansion scheme

PTA (daily question) 7-72 calculate the cumulative sum
随机推荐
PTA (daily question) 7-69 narcissus number
手把手教你安装Latex(保姆级教程)
Execute immediate simple sample set (DML)
MATLAB02:结构化编程和函数定义「建议收藏」
Error reporting: Rong Lianyun sends SMS verification code message 500
Cause analysis of 12 MySQL slow queries
云函数实现网站自动化签到配置详解【Web函数/Nodejs/cookie】
【愚公系列】2022年07月 Go教学课程 020-Go容器之数组
PTA (daily question) 7-73 turning triangle
Shell编程规范与变量
Yield Guild Games:这一年的总结与未来展望
华为发布HarmonyOS 3.0,向“万物互联”再迈一步
靠云业务独撑收入增长大梁,微软仍然被高估?
Relying on cloud business to support revenue growth alone, is Microsoft still overvalued?
Outlier detection and open set identification (2)
软考 --- 数据库(4)SQL语句
Solutions such as failed plug-in installation and slow speed of linking remote server under vscode
Meeting notification & meeting feedback & feedback details function of meeting OA project
【MySQL 8】Generated Invisible Primary Keys(GIPK)
DRF - paging, JWT introduction and principle, JWT quick use, JWT source code analysis, JWT custom return format, custom user issued token, custom token authentication class