[Go]---array

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Email: hahayacoder@gmail.com

The operation of the array in the Go language is relatively simple, and the C language is very similar, good, nonsense not much to say, directly on the code, I believe that all can understand

Package Mainimport "FMT" Func Main () {//declares an array var number [5]intfmt] that contains 5 int types. PRINTLN ("Array number:", number) FMT. PRINTLN ("Array len:", Len (number))//sets the value of the variable within the array number[1] = 1number[3] = 3fmt. PRINTLN ("Array number:", number)//defines an array in another way num: = [5]int{0, 1, 2, 3, 4}fmt. PRINTLN ("Array num:", num)///two-dimensional array var array2d [2][3]intfor I: = 0; I < 2; i++ {for J: = 0; J < 3; J + + {Array2d[i][j] = i + j}}fmt. Println ("Array2D:", array2d)//array of slicing operations a: = [5]int{0, 1, 2, 3, 4}//a[2], a[3] does not include a[4]b: = A[2:4]fmt. Println ("B:", B)//from a[0] to A[4] does not include a[4]c: = A[:4]fmt. Println ("C:", c)//from a[2] to A[4] includes a[2]d: = A[2:]fmt. Println ("D:", D)}


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.