Go pass by value

  Kiến thức lập trình

enter image description here

func (s *MyStruct) pointerMethod() { } // method on pointer
func (s MyStruct)  valueMethod()   { } // method on value

“Whether to define the receiver as a value or as a pointer is the same question, then, as whether a function argument should be a value or a pointer. There are several considerations”.

So may I conclude that everything is passed by value in the usual way, even for struct methods when they get called they provide a copy of what they are. If its a ptr struct it would give a ptr struct to a ptr receiver method otherwise a copy set to the method that is not a ptr receiver. And only exact matches are implemented.

New contributor

proworld1234youngpro1234 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT