Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posts/go/slice-discuss/ #159

Open
utterances-bot opened this issue Feb 14, 2022 · 2 comments
Open

posts/go/slice-discuss/ #159

utterances-bot opened this issue Feb 14, 2022 · 2 comments

Comments

@utterances-bot
Copy link

Go 切片这道题,吵了一个下午!

https://eddycjy.com/posts/go/slice-discuss/

Copy link

大佬,猜一下结果是什么

func main() {
s := make([]int, 0)
//s = []int{0, 10, 100}
s = append(s, 0)
s = append(s, 10)
s = append(s, 100)
fmt.Printf("main 内存地址:%p\n", s)
hello(s)
fmt.Println(s[0:len(s)])
fmt.Println(cap(s))
fmt.Println(s[0:cap(s)])
}

func hello(s []int) {
fmt.Printf("hello 内存地址:%p\n", s)
s = append(s, 1000)
s = append(s, 10000)
s = append(s, 100000)
s = append(s, 1000000)
s = append(s, 10000000)
s[0] = 1000
}

Copy link

fun4wut commented May 14, 2022

图挂了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants