Last active
October 25, 2020 03:26
-
-
Save 0xc0d/9c37a173dd236355b5a51e8eb4bd5ec2 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 { | |
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