Go language---value and pass 78893828
1. Definition:
b = A;
B.modify ();
If the modification of B does not change the value of a, then it is a pass value;
Most of the 2.golang are value-added and are:
Base type: byte,int,bool,string
Composite type: Array, array slice, struct, map,channnel
3. Arrays:
3.1 Pass Value
func main() { var array = [3]int{0, 1, 2} var array2 = array slice2[2] = 5 fmt.Println(array, array2)}
Output Result:
[0 1 2] [0 1 5]
3.2. How to use the reference:
func main() { var array = [3]int{0, 1, 2} var array2 = &array array2[2] = 5 fmt.Println(array, *array2)}
Output Result:
[0 1 5] [0 1 5]
4. Array slicing look at this blog post:
http://blog.csdn.net/cyk2396/article/details/78893420
5.struct Structural Body:
The arguments in the function can be passed as a value (the object is copied, a new space needs to be opened to store the new object) and a reference (the copy of the pointer, and the original pointer to the same object), the recommended use of pointers for two reasons: the ability to change the value of the parameter, to avoid large object copy operation to save memory. The use of struct and array is similar
6.map Read this blog post:
http://blog.csdn.net/cyk2396/article/details/78890185
7.channel:
Channel and array slices, like map, the way to pass a parameter is a value, can be used directly, which maintains a pointer to the real storage space.
Go language---Value and pass-through