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

边栏推荐
- Yield Guild Games:这一年的总结与未来展望
- [develop low code platform] low code rendering
- flask结合容联云发送验证码
- NPM run serve stuck at 40%
- About 1931cie -- conversion of XYZ color coordinate graph to RGB color coordinate relationship
- The 30th day of question brushing
- 17.机器学习系统的设计
- SAP vl02n delivery note posting function WS_ DELIVERY_ UPDATE
- Dynamic programming problem (VIII)
- [development tutorial 11] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - explanation of the function code of the whole machine
猜你喜欢

最长上升子序列

MySQL sub database and sub table and its smooth expansion scheme

Download the latest version of visual studio code and connect to the server remotely (very detailed)
![[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)

将Word中的表格以图片形式复制到微信发送

Flyway's quick start tutorial

IMG tags prohibit dragging pictures

将行内元素转换为块元素的方法

NPM run serve stuck at 40%

Oracle实例无法启动的问题如何解决
随机推荐
I was asked several questions about string in the interview. Can you answer them?
Depth first search (DFS) and its matlab code
Dynamic programming problem (2)
[develop low code platform] low code rendering
Upload Excel files with El upload and download the returned files
【MySQL 8】Generated Invisible Primary Keys(GIPK)
DRF - deserialization of serializer, fields and parameters, local and global hooks, use of modelserializer
flask结合容联云发送验证码
rk3399 9.0驱动添加Powser按键
Yield Guild Games:这一年的总结与未来展望
PTA (daily question) 7-70 diamond
Outlier detection and Gan network (1)
PTA (daily question) 7-73 turning triangle
SAP vl02n delivery note posting function WS_ DELIVERY_ UPDATE
PTA (daily question) 7-72 calculate the cumulative sum
MATLAB02:结构化编程和函数定义「建议收藏」
seleniumwire获取百度指数
Alibaba code index technology practice: provide reading experience of local IDE for code review
andriod6.0低功耗模式(关闭wifi、蓝牙、gps、屏幕亮度等)
NFTScan 与 NFTPlay 在 NFT 数据领域达成战略合作