文沐

vuePress-theme-reco wenmu    2020 - 2025
文沐 文沐

Choose mode

  • dark
  • auto
  • light
首页
文章
  • AI
  • Golang
  • Linux
  • 其他
文沐的书 (opens new window)
博客
  • 简书 (opens new window)
  • 博客园 (opens new window)
开源项目
  • 海芯导航 (opens new window)
  • 导出书签插件 (opens new window)
  • GoweAdmin
Github (opens new window)
Gitee (opens new window)
author-avatar

wenmu

15

Articles

18

Tags

    首页
    文章
    • AI
    • Golang
    • Linux
    • 其他
    文沐的书 (opens new window)
    博客
    • 简书 (opens new window)
    • 博客园 (opens new window)
    开源项目
    • 海芯导航 (opens new window)
    • 导出书签插件 (opens new window)
    • GoweAdmin
    Github (opens new window)
    Gitee (opens new window)
    • Golang

      • go-cache使用测试
      • 切片会修改数组的值
      • Recover需要在defer函数中调用
      • sqlx包
      • strings包

    切片会修改数组的值

    vuePress-theme-reco wenmu    2020 - 2025

    切片会修改数组的值

    wenmu 5/27/2021 Golang

    # 切片会修改数组的值

    通过修改数组切片的值,来改变数组元素的值

    package main
    
    import "fmt"
    
    func main() {
        x := [3]int{1, 2, 3}
        y := x[0:1]
    
        var _ = func(arr []int) int {
            arr[0] = 7
            fmt.Println(arr)
            return 7
        }(y)
    
        fmt.Println(x)
    }
    
    

    执行结果:

    [7]
    [7 2 3]
    

    go-cache使用测试 Recover需要在defer函数中调用