美文网首页Go
Go array & slice

Go array & slice

作者: JaedenKil | 来源:发表于2019-03-06 10:43 被阅读0次

A slice does not store any data, it just describes a section of an underlying array.

Changing the elements of a slice modifies the corresponding elements of its underlying array.

Other slices that share the same underlying array will see those changes.

When initialising a variable with a composite literal, Go requires that each line of the composite literal end with a comma, even the last line of your declaration.

package main

import "fmt"

func main() {
    names := [4]string{
        "Alice",
        "Jack",
        "Johnny",
        "Zed",
    }
    fmt.Println(names)

    a := names[0: 2]
    b := names[1: 3]
    fmt.Println(a, b)

    b[0] = "XXX"
    fmt.Println(a, b)
    fmt.Println(names)
}
[Alice Jack Johnny Zed]
[Alice Jack] [Jack Johnny]
[Alice XXX] [XXX Johnny]
[Alice XXX Johnny Zed]

相关文章

  • 深入理解 Go Slice

    原文地址:深入理解 Go Slice 是什么 在 Go 中,Slice(切片)是抽象在 Array(数组)之上的特...

  • Go array & slice

    A slice does not store any data, it just describes a sect...

  • Go - array、slice

    array 特征 内存连续,可以根据索引获取元素. 初始化之后大小就无法改变. 存储元素类型相同、大小相同的两个数...

  • 彻底理解Golang Slice

    看完这篇文章,下面这些高频面试题你都会答了吧 Go slice的底层实现原理 Go array和slice的区别 ...

  • go中array与slice

    刚接触go时间不长,关于array与slice做一个笔记 eg: eg2:

  • Go中的Array和Slice

    Go中的Array和Slice 翻译来于:https://blog.golang.org/slices 操作 ex...

  • Golang Range关键字的秘密

    Go 语言中 range 关键字用于 for 循环中迭代,支持类型如下: 数组(array) 切片(slice) ...

  • golang slice && array

    array 和slice都是数组,前者固定大小,值类型;后者可以动态变更,引用类型。再次强调一遍,array在go...

  • Go语言范围(Range)

    Go 语言中 range 关键字用于 for 循环中迭代数组(array)、切片(slice)、通道(channe...

  • 增强for循环 for range

    Go 语言中 range 关键字用于 for 循环中迭代数组(array)、切片(slice)、通道(channe...

网友评论

    本文标题:Go array & slice

    本文链接:https://www.haomeiwen.com/subject/vgttpqtx.html