Skip to content

Instantly share code, notes, and snippets.

@lmllrjr
Created January 19, 2023 10:13
Show Gist options
  • Save lmllrjr/3802598c503a79f44dec4ee73cacec9b to your computer and use it in GitHub Desktop.
Save lmllrjr/3802598c503a79f44dec4ee73cacec9b to your computer and use it in GitHub Desktop.
Create/use a pointer to a slice of pointers
// Check it out in go playground:
// https://go.dev/play/p/4FJZ7109K4U
package main
import "fmt"
func main() {
p := NewPointers()
fmt.Printf("\nthe complete pointer to slice of pointers (c): %#v\n", p)
fmt.Printf("\n(a)value of first entry (a): %#v\n", *(*p)[0])
fmt.Printf("\n(b)value of second entry (b): %#v\n", *(*p)[1])
}
// NewPointers creates a pointer to a slice of pointers of strings
func NewPointers() *[]*string {
a := "a"
b := "b"
c := make([]*string, 2)
c[0] = &a
c[1] = &b
return &c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment