Get the App
SLTechnology News&Howtos  ›  Development  › 

How to call functions in Go language

Shulou Source: shulou.com Published: 2022-06-01 02:31:42 09月12日 Update

This article mainly explains "how to call Go language functions". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to call Go language functions.

Function call

When you create a function, you define what the function needs to do and call the function to perform the specified task.

Call the function, pass parameters to the function, and return a value, such as:

Example

Package main

Import "fmt"

Func main () {

/ * define local variables * /

Var an int = 100

Var b int = 200

Var ret int

/ * call the function and return the maximum value * /

Ret = max (a, b)

Fmt.Printf ("maximum is:% d\ n", ret)

}

/ * the function returns the maximum of two numbers * /

Func max (num1, num2 int) int {

/ * define local variables * /

Var result int

If (num1 > num2) {

Result = num1

} else {

Result = num2

}

Return result

}

The above example calls the max () function in the main () function, and the execution result is:

The maximum value is: 200. so far, I believe you have a deeper understanding of "how to call Go language functions". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Functions maximum maximum language content variables examples local learning practical deeper two tasks interests parameters practicality practicality simple operation methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei vpn Redmi Linux