Golang: functions with return values


In this post I show you about how to create functions with return values in Go Programming Language.

Golang functions with return values (link) :

package main

import (
    "fmt"
)

var (
    function1 = func() {
        fmt.Println( function3() )
    }

    function2 = func() {
        fmt.Println( function4() )
    }

)

var function3 = func() string {
     return "Falls"
}

func function4() int {
     return 3
}

func accidents () (a string, b int) {
    a = function3()
    b = function4()
    return
}

func main () {
    function1()
    function2()

    x, y := accidents()

    fmt.Printf( "%s %d times", x, y )
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s