Last active
August 19, 2019 07:43
-
-
Save timruffles/5bc17fd7dbd644130001397c3b365394 to your computer and use it in GitHub Desktop.
What does this program output, and why? Reason it out gophers! Answers in a spoiler block - https://github.com/dear-github/dear-github/issues/166#issuecomment-236342209
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
package main | |
import "fmt" | |
func main() { | |
type person struct { | |
nickname string | |
} | |
ppl := []person{ | |
{ | |
nickname: "the knife", | |
}, | |
{ | |
nickname: "super hans", | |
}, | |
} | |
nicknames := make([]*string, 0) | |
for _, p := range ppl { | |
nicknames = append(nicknames, &p.nickname) | |
} | |
fmt.Println(*nicknames[0], *nicknames[1]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to run it; and I was initially wrong, but, I've assume
for _, p := range ppl
creates a copy of ppl at a new pointer...?