标签:初始化 ring div imp port fun printf int main
package main import "fmt" func main() { var s []student fmt.Printf("%T\n", s) //[]main.student fmt.Println(s) //[] //初始化结构体切片 s = []student{ { name: "yang", age: 18, }, } fmt.Println(s) //[{yang 18}] var s2 [5]student fmt.Printf("%T\n", s) //[]main.student fmt.Println(s2) //[{ 0} { 0} { 0} { 0} { 0}] //默认值空和零 //初始化结构体数组 s2 = [5]student{ { name: "yang", age: 18, }, } fmt.Println(s2) //[{yang 18} { 0} { 0} { 0} { 0}] } type student struct { name string age int }
标签:初始化 ring div imp port fun printf int main
原文地址:https://www.cnblogs.com/yzg-14/p/12283448.html