Last active
October 25, 2020 03:25
-
-
Save 0xc0d/4da09c3d2d6dc3f589434cd459817924 to your computer and use it in GitHub Desktop.
Using reference to loop iterator variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in := []int{1, 2, 3} | |
var out []*int | |
for _, v := range in { | |
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