Use the * number in go to denote the pointer, but there is no pointer arithmetic and it cannot be added or reduced. While memory management is run by go, you do not need to drag to free up memory.
The function recipient in go can be a value type or a reference type.
Look at the code:
Package main Import ("FMT") Type Rectstruct{X, Y,area,length float64} func (R*Rect) Calarea () {R.area= r.x*R.y}func (R Rect) Callength () {r.length=2* (r.x+r.y)} Func Main () {r1:= rect{3,4,0,0}r1. Calarea () R1. Callength () fmt. Println (R1. Area) FMT. Println (R1. Length) R2:= &rect{3,4,0,0}R2. Calarea () R2. Callength () fmt. PRINTLN (R2. Area) FMT. PRINTLN (R2. Length)}
Operation Result:
12
0
12
0
You can see the code running here directly:
Http://play.golang.org/p/ZleGPoyuEp
As you can see from the code above:
1, go in the function receiver can be understood as a function of a parameter, if you pass a reference, you can change the value in the calling function.
2, in addition to the receiver need to use * to indicate that the pointer, in the calling function and the called function * and the & symbol is not necessary, go will be called function and use parameters at the same times according to the receiver to do the conversion.
Pointers and function receivers in go