Arrays in the Go language

Source: Internet
Author: User
Tags array length

Package Main;import ("FMT") func main () {//declares an array var a [3]int;a = [3]int{1, 2, 3};//declares and assigns var b [3]int = [3]int{1, 2, 3};//Sound Ming and Assignment (ellipsis type) var c = [3]int{1, 2, 3};//Declaration and assignment Shorthand D: = [3]int{1, 2, 3};//go the array length as part of the array type//e and F are two different types of variables, they cannot be assigned to the Operation Var e [2] Int;var F [3]int;//Specify the subscript initial 0 value, set the last element to 1var g [20]int = [20]int{19:1};//use ... Let go automatically calculate the array length h: = [...] Int{1, 2, 3, 4, 5};//go automatically calculates the required array length, the same variable gi: = [...] The elements of the int{19:1};//array are pointers, and the elements of the J array are a pointer to an int AA: = 1;bb: = 2;j: = [...] *INT{&AA, &bb};//Pointer to an array of k: = [5]int{1, 2, 3, 4, 5};//m is a pointer to an array of var m *[5]int = &k;//array comparison n: = [2]int{1, 2};o : = [2]int{1, 2};//returns a pointer to the array by new P: = new ([2]int);//can also be used [] to assign p[0], p[1] = 1, 2;//multidimensional array, two rows two columns Q: = [2][2]int{{1, 2}, {3, 4} };//automatically calculates multidimensional arrays, which must be top-level r: = [...] [2]int{{1, 2}, {3, 4}, {5, 6}};fmt. Printf ("%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n", A, B, C, D, E, F, G, H, I, J, m);//Array compare FMT. PRINTLN (n = = O); fmt. PRINTLN (P); fmt. PRINTLN (q); fmt. Println (r);}

  

Arrays in the Go language

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.