Go 结构体指针 - go 训练营

type Employee struct { ID int Name string Address string DoB time.Time Position string Salary int ManagerID int } var dilbert Employee 结构体字段可以通过结构体指针来访问。 position := &dilbert.Position *position = "Senior " + *position 点号同样可以用在结构体指针上, var employee *Employee = &dilert (*employee).Position += " (MVP)" Go 语言也允许我们使用隐式间接引用,直接写 employee.Position 就可以。
欢迎参加 Go 训练营挑战,这些挑战将帮助你逐步掌握 Go 开发。Go(又称Golang)是 Google 开发的一种静态强类型、编译型、并发型,并具有垃圾回收功能的编程语言。在 2016 年,Go 被软件评价公司 TIOBE 选为“TIOBE 2016年最佳语言”。