go - How to return slice by reference? -
the returned slice reference empty:
package main import "fmt" func getitems(items *[]string) { list := make([]string, 0) list = append(list, "ok") items = &list } func main() { var items []string getitems(&items) fmt.print(len(items)) // expect 1 here, got 0 }
how return slice function reference?
by assigning items
, alter items
points, not value items
points to. latter, instead of items = &list
write *items = list
.
Comments
Post a Comment