Changing a slice by passing its pointer
问题 I have a slice that I want to change (for example i want to remove the first element) using a function. I thought to use a pointer, but I still can't index it. What am I doing wrong? Playground link: func change(list *[]int) { fmt.Println(*list) *list = *list[1:] //This line screws everything up } var list = []int{1, 2, 3} func main() { change(&list) } 回答1: You need to use (*list) . func change(list *[]int) { *list = (*list)[1:] } or a different approach that's usually more go idomatic: func