Go language---Value and pass-through

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.