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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| package main
import "fmt"
type Teacher struct { name string age int8 sex byte }
func main() {
var t1 Teacher fmt.Println(t1) fmt.Printf("t1:%T , %v , %q \n", t1, t1, t1)
t1.name = "Steven" t1.age = 35 t1.sex = 1 fmt.Println(t1) fmt.Println("-------------------")
t2 := Teacher{} t2.name = "David" t2.age = 30 t2.sex = 1 fmt.Println(t2) fmt.Println("-------------------")
t3 := Teacher{ name: "Josh", age: 28, sex: 1, } t3 = Teacher{name: "Josh2", age: 27, sex: 1} fmt.Println(t3) fmt.Println("-------------------")
t4 := Teacher{"Ruby", 30, 0} fmt.Println(t4) fmt.Println("-------------------")
t5 := new(Teacher) fmt.Printf("t5:%T , %v , %p \n", t5, t5, t5)
t5.name = "Running2" t5.age = 31 t5.sex = 0 fmt.Println(t5) fmt.Println("-------------------") }
|