Tsallaka zuwa abun ciki
Justice Tech School

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 31

Exercise

Define a struct.

type P  {}

Quiz Test

How do you read a field?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.