Golang是有指针概念的,想写好这门语言,避免空指针的错误还是要花点功夫的。先看看例子
package main
import (
"fmt"
)
type Student struct {
Age int
}
func main() {
arr := [3]Student{
{
Age: 10,
},
{
Age: 15,
},
{
Age: 20,
},
}
for _, v := range arr {
v.Age = 0
}
fmt.Println(arr)
}
...