当前位置:网站首页>[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)
}
}

边栏推荐
- Dynamic programming problem (VII)
- Common sparse basis and matlab code for compressed sensing
- 直流无刷电机控制器(换电机霍尔收费多少)
- DRF - web development mode, API interface, API interface testing tool, restful specification, serialization and deserialization, DRF installation and use
- Common measurement matrix and matlab code of compressed sensing
- Isolation level of MySQL, possible problems (dirty reading, unrepeatable reading, phantom reading) and their solutions
- [untitled]
- CDN mode uses vant components, and components cannot be called after they are introduced
- PTA (daily question) 7-77 encryption
- Download the latest version of visual studio code and connect to the server remotely (very detailed)
猜你喜欢

Dynamic programming (V)

IMG tags prohibit dragging pictures

从零开始实现lmax-Disruptor队列(六)Disruptor 解决伪共享、消费者优雅停止实现原理解析

2022dasctfjuly empowerment competition (reappearance)

NFTScan 与 NFTPlay 在 NFT 数据领域达成战略合作

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

15.模型评估和选择问题

PTA (daily question) 7-77 encryption

selenium对接代理与seleniumwire访问开发者工具NetWork

PTA (daily question) 7-69 narcissus number
随机推荐
Shell programming specifications and variables
多线程顺序运行的几种方法,面试可以随便问
会议OA项目之会议通知&会议反馈&反馈详情功能
Alibaba code index technology practice: provide reading experience of local IDE for code review
【开发教程11】疯壳·开源蓝牙心率防水运动手环-整机功能代码讲解
Techo Hub 福州站干货来袭|与开发者共话工业智能新技术
Dynamic programming problem (VII)
Basic knowledge of PHP language (super detailed)
110 MySQL interview questions and answers (continuously updated)
Talk about seven ways to realize asynchronous programming
异步模式之工作线程
PTA (daily question) 7-70 diamond
PTA (daily question) 7-73 turning triangle
SQL Server 只有数据库文件,没有日志文件,恢复数据时报1813错误的解决方案
"Food alliance ordering system"
PTA (daily question) 7-74 yesterday
16.偏差、方差、正则化、学习曲线对模型的影响
Send SMS verification code asynchronously using Ronglian cloud celery
SAP vl02n delivery note posting function WS_ DELIVERY_ UPDATE
Requestvideoframecallback() simple instance