结构体之间的转换

This commit is contained in:
2025-11-17 16:11:56 +08:00
parent a83e2005c6
commit 97f9683c73

39
main.go
View File

@@ -3,31 +3,20 @@ package main
import "fmt"
func main() {
//创建结构体
var t1 Teacher
fmt.Println(t1)
t1.Name = "马泽"
t1.Age = 45
t1.School = "清华大学"
fmt.Printf("%p\n", &t1)
fmt.Println(t1)
fmt.Println(t1.Name)
var t2 = Teacher{"马碧", 44, "马龙大学"}
fmt.Println(t2)
var t3 = new(Teacher)
(*t3).Name = "ssh"
(*t3).Age = 45
(*t3).School = "阿米诺斯"
fmt.Printf("%p\n", &t3)
fmt.Println(t3)
fmt.Println(*t3)
var s1 Student
var s2 Stu
s1.Age = 10
s2.Age = 20
fmt.Println(s1)
fmt.Println(s2)
s1 = Student(s2)
fmt.Println(s1)
}
// Teacher 结构体的定义
type Teacher struct {
Name string
Age int
School string
type Student struct {
Age int
}
type Stu struct {
Age int
}