Type system

Go struct types

Groups named fields into one value. Struct assignment copies field values; comparability requires all fields to be comparable. Example output: '2 9'.

Formal Syntax & Structure

go syntaxgo
struct { Field T }

Working Example

Example Snippetgo
package main
import (  "fmt")
func main() {  type Point struct{ X, Y int }  p := Point{X: 2, Y: 3}  q := p  q.X = 9  fmt.Println(p.X, q.X)}
Go Reference