Go Learning--arrays

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
An array is a value type in go, and if you assign an array to another array, it is actually a copy of the entire array
Array definitions: var <arrName> [N]<type>, n>=0. n If the size is different, the array type is not the same
You can use = = and! = to compare between arrays of the same type, but you cannot use < and >
Arrays of the same type can be assigned directly: var a = [10]int{1,2,3, 5:9} var b [10]int b =a
Array pointers and array of pointers
When you create an array with new, an array pointer is returned
var arrname [10]int//Array definition
var arr = [5]int{9, 5, 6, 1, 4}//Initialization
var arr = [5]int{9, 5, 4:9}//initialization, 4:9 index
Arr: = [5]int{9, 5, 6, 1, 4}//Initialization
Bubble sort
Func Main () {
var arr = [5]int{9, 5, 4:9}
For I: = 0; I < Len (arr); i++ {
For J: = i + 1; J < Len (arr); J + + {
If ARR[J] > Arr[i] {
ARR[J], arr[i] = Arr[i], arr[j]
}
}
}

Fmt. Println (arr)
}
Multidimensional arrays
var a = [2][2]int{[2]int{1,1}, [2]int{2,2}}
var a = [2][2]int{{1,1}, {2,2}}



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.