Structs
A struct groups fields. Create with a literal and use . to access.
Example
package main
import "fmt"
type P struct {
Name string
Age int
}
func main() {
p := P{Name: "Ada", Age: 30}
p.Age++
fmt.Println(p, p.Name, p.Age)
}Result
{Ada 31} Ada 31Exercise
Define a struct.
type P {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.