1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| package main
import "fmt"
/* 结构体: type struct_variable_type struct{ member definition; member definition; ... member definition; } */
type student struct{ name string id int sex bool; school string }
func main() { var st1= student{"张三", 12, true, "西安邮电大学"} st2 := student{"张三", 12, true, "西安邮电大学"} fmt.Println(st1) fmt.Println(st2)
var st3 student st3.name = "李四" st3.id = 13 st3.sex = false st3.school = "西安邮电大学" fmt.Println(st3)
var st4 = [3]student{ {"张三", 12, true, "西安邮电大学"}, {"张三", 12, true, "西安邮电大学"}, {"张三", 12, true, "西安邮电大学"}, }
fmt.Println(st4) }
|