Literal
Keyed and positional struct literals
Keyed struct literals can omit fields, which receive zero values. Positional literals must supply all fields in declaration order. Do not mix forms. Go 1.27 adds nested field selector keys; this example uses direct fields. Example output: '{0 4} {1 2}'.
Formal Syntax & Structure
go syntaxgo
T{Field: value}; T{value1, value2}Working Example
Example Snippetgo
package main
import "fmt"
type Point struct{ X, Y int }
func main() { fmt.Println(Point{Y: 4}, Point{1, 2})}