Golang Pass by Reference

//http://openmymind.net/Things-I-Wish-Someone-Had-Told-Me-About-Go/
//http://play.golang.org/p/ykjG9Thews
package main
import (
    "fmt"
)

type User struct {
    Name string
}

func Modify(u *User) {
    u.Name = "Duncan"
}

func main() {
    u := User{Name: "Leto"}
    fmt.Println(u.Name)
    Modify(&u)
    fmt.Println(u.Name)

    //output
    //Leto
    //Duncan
}

					
Advertisements

Subjectivity aside, 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