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

Popular posts from this blog

angularjs - Showing an empty as first option in select tag -

qt - Change color of QGraphicsView rubber band -

c++ - Visible files in the "Projects" View of the Qt Creator IDE if using the CMake build system -