Go function simple example

In this example, we will show you how to create a simple function in Go with an example.

A function is a mapping of zero or more input parameters to zero or more output parameters.

Go function simple example

Functions in Go are created with the func keyword. We use the return keyword to return values from functions.

The following example creates a simple function in Go:

package main

import "fmt"

func main() {

    x := 4
    y := 5

    z := add(x, y)

    fmt.Printf("Output: %d\n", z)

func add(a int, b int) int {

    return a + b


Output: 9

In the above example, we define a function that adds two values.

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course