1 Star 0 Fork 0

c01dface/s-go-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
arrays.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
c01dface 提交于 2024-11-06 09:58 . add arrays.go
package main
import "fmt"
func main() {
// create an array a that will hold exactly 5 ints.
// The type of elements and length are both part of the
// array's type. By default an array is zero-valued.
var a [5]int
fmt.Println("emp:", a)
// we can set a value at an index using the array[index] = value syntax
// and get a value with array[index]
a[4] = 100
fmt.Println("set:", a)
fmt.Println("get:", a[4])
// the builtin len returns the length of an array
fmt.Println("len:", len(a))
// Use this syntax to declare and initialize an array in one line
b := [5]int{1, 2, 3, 4, 5}
fmt.Println("dcl:", b)
// you can also have the compiler count the number of elements for you with ...
b = [...]int{1, 2, 3, 4, 5}
fmt.Println("dcl:", b)
// if you specify the index with :, the elements in between will be zeroed
b = [...]int{100, 3: 400, 500}
fmt.Println("dcl:", b)
// Array types are one-dimensional, but you can compose types to
// build multi-dimensional data structures.
var twoD [2][3]int
for i := 0; i < 2; i++ {
for j := 0; j < 3; j++ {
twoD[i][j] = i + j
}
}
fmt.Println("2d: ", twoD)
// you can create and initialize multi-dimensional arrays at once too
twoD = [2][3]int{
{1, 2, 3},
{3, 4, 5},
}
fmt.Println("2d: ", twoD)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vmalloc/s-go-example.git
git@gitee.com:vmalloc/s-go-example.git
vmalloc
s-go-example
s-go-example
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385