pointers1

command
v0.0.0-...-a2a1f02 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 1 Imported by: 0

README

pointers1 example

A struct passed to function by value (copy) and by address (reference).

GitHub Webpage

PASS BY REFERENCE (MAKES POINTER IN FUNCTION)

Passing the address of a struct to a function (by reference),

b := person{"Jill", "female", 27}
changeNamePtr(&b)

So the function can now work on that original struct,

func changeNamePtr(p *person) {
    p.name = "Lisa"
}

In this case the name is changed from Jill to Lisa.

This diagram may help,

IMAGE - pointers1 - IMAGE

RUN

Run,

go run pointers1.go

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL