Third glance in Go

Source: Internet
Author: User

In go language, the use of arrays, slices (Slice) and Mapping Tables (map) is often seen. People who have a background in other languages will be more familiar with it, but it is also because of the familiarity that leads to a habit of thinking that often kicks "stone", and I am one of them. Let's say the number of questions:

Nothing else, but in the case of the passing number of the needle to the function, go is like this if you want to pass a number of needles into a function, you have to make sure the size of the numbers

*[] int ) {    arr[21}func Main () {    arr:new([int.]int )    UpdateItem (arr)}

That's not going to work, and I'll give you a type of mismatch bug that you must write

Func UpdateItem (arr *[]int) {    arr[21}

In addition to the needle, you can also use slices to pass the numbers, but this is not the way to go.

Func UpdateItem (arr []int) {    arr[21}func Main () {    arr: New ([+]int)    UpdateItem (arr[:])}

Another doubt is the length of the slice and the definition of capacity, do not know how to make ([]int, 10, 50), how to fill after 40 memory space value? It is possible to access the following 40 spaces through the expansion of the slices. Tile re-expansion must start at 0, as

var slice1 = make ([]int= slice1[0: Len (slice1) +1 ]

This adds a space to the slice.

Third glance in Go

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.