Relationship of the [GO] slice and the underlying array

Source: Internet
Author: User

Package Mainimport"FMT"Func Main () {a:= []int{0,1,2,3,4,5,6,7,8,9} S1:= a[2:5] s1[1] =444FMT. Println ("S1 =", s1) S2:= s1[1:6] s2[1] =555FMT. Println ("s2 =", S2) fmt. Println ("A =", a)}

The result of the execution is:

S1 =  [24444=  [444555567 = [0 1 2 444 555 5 6     789]

The results can be seen, although the S1 array is intercepted, we see the result is also intercepted fragments, but it just shows what we want to see, the other after it still exists the value of the original slice

And by making changes to the new slices, the elements of the original slices have also changed.

From the experiment, the results are the same, whether a is an array or a slice.

Relationship between the [GO] slice and the underlying array

Related Article

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.