Skip to content

Types & Data

Every value in Go has a static type known at compile time. Go divides its types into two broad families:

Value types — variables hold the data directly. Assigning one variable to another copies the data. The primitive value types are booleans, numeric types (int, int64, float64, uint8, …), and string. Composite value types are arrays and structs.

Reference-like types — the variable holds a small header that points to a backing data structure allocated elsewhere. Slices, maps, channels, functions, and pointers all fall into this family. Assigning copies the header, not the underlying data, so two variables can observe the same data.

flowchart TD
  Root["Go Type Taxonomy"]
  Root --> Value["Value types (copy on assign)"]
  Root --> Ref["Reference-like (header copied)"]
  Value --> V1["bool, int, float64, string"]
  Value --> V2["[N]T (array)"]
  Value --> V3["struct { ... }"]
  Ref --> R1["*T (pointer)"]
  Ref --> R2["[]T (slice)"]
  Ref --> R3["map[K]V"]
  Ref --> R4["chan T, func(...)"]
Go types split into value types (copied on assign) and reference-like types (header copied)
LessonTopic
This pageType landscape and a first program
StructsDefining structs, embedding, comparison
SlicesArrays vs slices, make, append, copy
Mapsmake(map[K]V), comma-ok, delete, iteration
Pointers& and *, mutation, nil pointers

The program below defines a Point struct, builds a []Point slice, then looks up a name in a map[string]int. It demonstrates value types (Point is copied), slice literals, and map access with the zero-value default.

package main
import "fmt"
type Point struct {
X, Y int
}
func main() {
// Struct literal with named fields
p := Point{X: 3, Y: 4}
fmt.Println(p.X, p.Y)
// Slice of structs
points := []Point{
{X: 0, Y: 0},
{X: 1, Y: 2},
{X: 3, Y: 4},
}
for _, pt := range points {
fmt.Printf("(%d, %d)\n", pt.X, pt.Y)
}
// Map: string -> int
score := map[string]int{
"Alice": 95,
"Bob": 87,
}
fmt.Println(score["Alice"])
fmt.Println(score["Charlie"]) // missing key -> zero value (0)
}
Which of the following is a value type in Go — meaning assignment copies the data?
What does Go print when you read a map key that has never been set?
A `[]Point` slice and a `[3]Point` array both store Point values. What is the key difference?