Skip to content

Instantly share code, notes, and snippets.

@0xc0d
Last active October 25, 2020 03:26
Show Gist options
  • Save 0xc0d/9c37a173dd236355b5a51e8eb4bd5ec2 to your computer and use it in GitHub Desktop.
Save 0xc0d/9c37a173dd236355b5a51e8eb4bd5ec2 to your computer and use it in GitHub Desktop.
Using reference to loop iterator variable
in := []int{1, 2, 3}
var out []*int
for _, v := range in {
v := v
out = append(out, &v)
}
fmt.Println("Values:", *out[0], *out[1], *out[2])
fmt.Println("Addresses:", out[0], out[1], out[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment