Golang variable Parameters

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
Code by Shaoyongyangpackage mainimport ("FMT") var t int = 1var Fslice []intfunc Main () {dosomething (1, 2, 3, 4) Return}func dosomething (arg ... int) {FMT. PRINTLN (ARG)//As a slice fslice: = []int (ARG) fmt. Println (fslice[2])}


var fslice[] Int declares a variable like a "dynamic array" here. No limit on length

The type of the mutable parameter is int.

You can only pass data that can be converted.

For example I can pass dosomething (1, ' A ', 3, 4)

The Ascill code for ' a ' is 65.


The following are all wrong:

DoSomething (1, 3.1415926, 3, 4)//Loss Accuracy

DoSomething (1, "span", 3, 4)//not the same type


So it can be concluded that:

Go variable parameters, parameters are the same type, or can be converted without loss of data accuracy

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.