Examples of Go language function parameters and return values, simple application of arrays

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

Examples of Go language function parameters and return values, simple application of arrays

 PackageMainImport "FMT"funcMain () {string1, string2: =test_various_values( in, the) FMT. Println ("Parameter 1", string1) fmt. Println ("Parameter 2", string2) fmt. Println ("------------------------------------------------------------------") V1, V2: =test_various_values2( in,"Huangmao") FMT. Println ("--v1====", v1) fmt. Println ("---v2 = =", v2) fmt. Println ("------------------------array traversal----------------------------------") Declaratetype ()}/** * Test multiple input return value functions *arg1,arg2 for incoming parameters, int specifies the type for the incoming parameter;  *STR1,STR2 is the return value parameter. *  */ funcTest_various_values (arg1,arg2int) (str1string, str2string) {FMT. Println ("a===", arg1) fmt. Println ("b===", arg2) fmt. Println ("a+b=", ARG1+ARG2) str1="Hell"Str2="World"    varMunintMun=34Fmt. Println ("num raw value = =", Mun) mun=arg1 fmt. Println ("num copy result = =", Mun)returnSTR1,STR2}funcTest_various_values2 (arg1int, arg2string) (RESLUT1int, Reslut2string){varNumintNum=arg1 FMT. Println ("Parameter 1====test_various_values2====", num)varV1stringV1=arg2 FMT. Println ("Parameter 2=====test_various_values2==", v1) Reslut1=num reslut2=v1returnRESLUT1, Reslut2}/** * Define variable * */ funcDeclaratetype () {varZ_numintZ_num=45Fmt. Println (Z_num)varStr1stringstr1="Hello go"Fmt. Println (STR1)//define Arrays   varMyArray[Ten]intmyarray=[Ten]int{1,2,3,4,5,6,7,8,9,Ten} forI: =0; I <Len(MyArray); i++ {fmt. Println ("Output array value ===myarray===="I"====", Myarray[i])}//Create an array slice based on the first 5 elements of a myarray:     varMyslice = myarray[: 5] forI: =0; I <Len(Myslice); i++ {fmt. Println ("Output array value ==myslice==="I"====", Myslice[i])}varMybehind=myarray[5:] forI: =0; I <Len(Mybehind); i++ {fmt. Println ("Output array value ==mybehind==="I"====", Mybehind[i])}}

For an introduction to related arrays See: http://studygolang.com/articles/2894

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.