Aashish's blog

Method, interface and pointers in golang

• go, and golang

go play link

type struct1 struct {
	greeting string
}

func (s *struct1) hello() {
	s.greeting = "hello"
}

func main() {
	ptr_s1 := &struct1{}
	fmt.Printf("ptr_s1 is of type : %+T\n", ptr_s1) // *main.struct1
	fmt.Printf("ptr_s1.greeting: %+v\n", ptr_s1)    // &{greeting:}

	ptr_s1.hello()
	fmt.Printf("ptr_s1.greeting: %+v\n", ptr_s1) // &{greeting:hello}

	s1 := struct1{}
	fmt.Printf("s1 is of type : %+T\n", s1) // main.struct1
	fmt.Printf("s1.greeting: %+v\n", s1)    // {greeting:}

	s1.hello()
	fmt.Printf("s1.greeting: %+v\n", s1) // {greeting:hello}
}