package main import "fmt" type Counter struct{ n int } // pointer receiver: mutates the caller's value func (c *Counter) Inc() { c.n++ } func main() { c := Counter{} c.Inc() c.Inc() fmt.Println(c.n) // 2 }
*T receiver changes the original