Go by Example:functions

Source: Internet
Author: User

function is the core of go, and we will learn about functions through a number of different examples.

Package Mainimport "FMT"    //This function inputs two int data, calculates and returns the int type and the Func plus (a int, b int) int {    //GO need to return the value    explicitly using the return statement It does not automatically return the value of the last expression in the function.    return a + b}func main () {    //As you would think, call the function res through "name (args)"    : = Plus (1, 2)    FMT. Println ("1+2 =", res)}

Output

$ go Run functions.go 1+2 = 3

The functions of the go language also have some other functions. One of these is the multi-valued return that will be learned in the next section.


Next example: Go by Example:multiple Return Values.


English original



Go by Example:functions

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.