English 中文(简体)
我是新来的,我不敢肯定,为什么结果不是我所期望的。
原标题:I am new to golang programming, I m not sure why the results are not what I expected!
  • 时间:2024-03-12 02:46:13
  •  标签:
  • go
package main

import (
    log "github.com/sirupsen/logrus"
)

func printSlice(slice []int) {
    slice[0] = 11
    log.Infof("sli %o", slice)
}

func main() {
    arr := [...]int{1, 2, 3, 4, 5, 6}
    log.Infof("Arr out %o", arr)
    slice := arr[3:]
    printSlice(slice)
    log.Infof("sli out %o", slice)
    log.Infof("Arr out2 %o", arr)
}

其结果为何:

time="2024-03-12T11:38:44+09:00" level=info msg="Arr out [1 2 3 4 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="sli [13 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="sli out [13 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="Arr out2 [1 2 3 13 5 6]"

我认为,结果应当是:

time="2024-03-12T11:38:44+09:00" level=info msg="Arr out [1 2 3 4 5 6]" 
time="2024-03-12T11:38:44+09:00" level=info msg="sli [11 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="sli out [11 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="Arr out2 [1 2 3 11 5 6]"

我的田地版本是1.18.10。

问题回答




相关问题
minimum work size of a goroutine [closed]

Does anyone know approximately what the minimum work size is needed in order for a goroutine to be beneficial (assuming that there are free cores for the work to be offloaded to)?

How do you get the terminal size in Go?

How do I get the terminal size in Go. In C it would look like this: struct ttysize ts; ioctl(0, TIOCGWINSZ, &ts); But how to i access TIOCGWINSZ in Go

What do you use to write Go [closed]

I know its a bit too early, but I ve been trying out Go (Google s Programming Language) and its kindof annoying to write code in gedit. So, my question: What do you use to experiment with Go?

Shared memory vs. Go channel communication

One of Go s slogans is Do not communicate by sharing memory; instead, share memory by communicating. I am wondering whether Go allows two different Go-compiled binaries running on the same machine to ...

Embedding instead of inheritance in Go

What is your opinion of this design decision? What advantages does it have and what disadvantages? Links: Embedding description

热门标签