This is a creation in Article, where the information may have evolved or changed.
1. For normal functions, when the recipient is a value type, the data of the pointer type cannot be passed directly, and vice versa.
2. For methods such as the method of a struct, when the recipient is a value type, you can call the method directly with a variable of pointer type, and vice versa.
The following is a simple example:
Package structtest//the difference between a normal function and a method (when the recipient is a value type and a pointer type)//date:2014-4-3 10:00:07import ("FMT") func structtest06base () { structTest0601 () structTest0602 ()}//1. function of the normal function//Receive value type parameter func valueinttest (a int) int {return a + 10}//receive pointer type argument function func Pointerinttest (a *int) int {return *a + 10}func structTest0601 () {A: = 2fmt. Println ("Valueinttest:", Valueinttest (a))//The parameter of the function is a value type, you cannot pass the pointer directly as a parameter//fmt. Println ("Valueinttest:", Valueinttest (&a))//compile error:cannot use &a (type *int) as type int in function Argum ENTB: = 5fmt. Println ("Pointerinttest:", Pointerinttest (&B))///Similarly, when a function's argument is a pointer type, the value type cannot be passed directly as a parameter//fmt. Println ("Pointerinttest:", Pointerinttest (b))//compile Error:cannot use B (Type int.) as type *int in function argument}//2 . method type Persond struct {ID intname string}//receiver is a value type func (P persond) Valueshowname () {fmt. The Println (p.name)}//recipient is a pointer-type func (P-*persond) Pointshowname () {fmt. Println (p.name)}func structTest0602 () {//value type Call method Personvalue: = persond{101, "'ll Smith"}personvalue.valueshowname () PersoNvalue.pointshowname ()//pointer type call method Personpointer: = &persond{102, "Paul Tony"}personpointer.valueshowname () Personpointer.pointshowname ()//Unlike normal functions, the recipient is a method of pointer type and value type, and variables of pointer type and value type can be called each other}