3 ms·
for a no-goer: will this copy by value? ``` var fred Student for _, student := range students { if student.name == "fred" { fred = stude
by singularity2001 9y ago
for a no-goer: will this copy by value?
```
var fred Student
for _, student := range students {
if student.name == "fred" {
fred = student
}
}
```
- majewsky 9y agoYes. A copy into type `Student` will copy each field, whereas `*Student` only takes the address. (Which would not be a problem if the loop didn't reuse the memory slot for the loop variable.) Also, indent with two spaces to get code formatting. HN formatting is (sadly) not Markdown.