go-learning/tour_of_go/l4/structs.go

28 lines
299 B
Go
Raw Permalink Normal View History

2025-08-30 12:55:18 +00:00
package main
import "fmt"
type Vertex struct {
X int
Y int
}
var (
v1 = Vertex{1, 2}
v2 = Vertex{X: 1}
v3 = Vertex{}
p = &Vertex{1, 2}
)
func main() {
v := Vertex{1, 2}
v.X = 4
fmt.Println(v)
o := &v
o.X = 12
fmt.Printf("New vertex value is %d\n", v)
fmt.Println(v1, p, v2, v3)
}