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

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

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

php - Cloud9 cloud IDE and CakePHP -