Go language Learning note eight: arrays

Source: Internet
Author: User

Go language Learning note eight: arrays

Array of earth people know. So just talk about the special (wonderful) wording of the go language.
I've been thinking about a person who has been involved in the design of two languages, but the grammar of the last two languages is quite different. This is self-denial, why not with the previous reunification.

Declaring an array
var variable_name [SIZE] variable_type

Example:

var x [10] int
Initializing an array
var x = [5] int {1, 2, 3, 4, 5}var y = [...] int {1, 2, 3, 4, 5}

The number of elements in the {} initialization array cannot be greater than the number in [].
If you ignore numbers in [] without setting the array size, the Go language sets the size of the array based on the number of elements.

Multidimensional arrays
var variable_name [SIZE1][SIZE2]...[SIZEN] variable_typevar x [5][10][4]int

Initializing a multidimensional array

a = [3][4]int{   {0, 1, 2, 3} ,   /*  第一行索引为 0 */ {4, 5, 6, 7} ,   /*  第二行索引为 1 */ {8, 9, 10, 11}   /*  第三行索引为 2 */}
Passing an array to a function
void myFunction(param [10]int) {}或者void myFunction(param []int) {}

Other articles in this series address:
Https://github.com/zhangqunshi/golang_study

Go language Learning note eight: arrays

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.