An array of Go language learning

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

1. Declare an array var a[2] int or a:=[2]int{1,2}

2. Array index
Arrays are indexed to create the

Let's have another test.

3.go languages can automatically calculate the length of an array, for example you know how many of the array can be stated below
[PHP]
A:=[...] INT{1,2,3,45}
[/php]
4. Array of pointers
[PHP]
a:=[3]int{1,2,3}
var p * [3]int = &a//This is an array of pointers we see that we can directly output pointers to arrays
X, y: =1, 3
A: = [...] *int{&x, &y}
Str. Println (a)//output such [0xc080000068 0xc080000070] address this is the array pointer
[/php]
You can use the New keyword to declare
[PHP]
P: = new ([10]int)
Fmt. PRINTLN (p)//&[0 0 0 0 0 0 0 0 0 0] Output a pointer
[/php]
Multidimensional arrays as in other languages
[PHP]
c: = [3][2]int{{1:2}, {2, 1}, {2, 2}}
Fmt. PRINTLN (c)//output [[0 2] [2 1] [2 2]]
[/php]
Bubble algorithm's Go language version
[PHP]
Package Main

Import "FMT"

Func Main () {
A: = [...] Int{3, 2, 5, 8, 6}
Fmt. Println (a)
Num: = Len (a)
For I: = 0; i < num; i++ {
For J: = i + 1; J < num; J + + {
If a[i] < A[j] {
Temp: = A[i]
A[i] = A[j]
A[J] = Temp
}
}
}
Fmt. Println (a)
}
[/php]

Without permission, do not reprint this site any article: Micro Network emoji language learning array

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.