Go · Stage 7 – Structuring Data · Lesson 41 of 64

What Is a Struct?

Understand a struct as a custom-shaped box with labeled compartments.

Go code

type Person struct {
    Name string
    Age  int
}
Line-by-line explanation
  1. Type creates a new named type.
  2. Person is the type name.
  3. Struct begins the field list.
  4. Name stores text and Age stores an integer.
Expected output
(no output)

A type definition changes what the program can create but prints nothing.