Pointers or values: when to use * and & in Go parameters and return values?
Hello everyone! I recently started learning Go, and I keep struggling with the question: when should I pass parameters to a function by pointer, and when by value? Same question for return values.
I kind of understand that pointers allow avoiding data copying, but doesn't Go copy everything anyway? Or not? I wrote a small example where I create a User struct and try to modify it:
```go
type User struct {
Name string
Age int
}
func updateUser(u User) {
u.Name = "New Name" // doesn't work as expected
}
func updateUserPtr(u *User) {
u.Name = "New Name" // works
}
```
But here's what confuses me: I thought everything in Go is passed by value, but slices and maps behave like references? Or not? I've read that large structs are better passed by pointer, ch