Files
go-playground/go-by-example/pointers/pointers.go
2026-03-02 09:40:31 +01:00

27 lines
517 B
Go

package main
import "fmt"
// This functions creates a copy of the argument and does not change the original
func zeroval(ival int) {
ival = 0
}
// Changes the value of the argument because it is a pointer.
func zeroptr(iptr *int) {
*iptr = 0
}
func main() {
i := 1
fmt.Println("initial", i)
zeroval(i)
fmt.Println("zeroval", i)
// & operand means the address of the variable. Creates a pointer when a function needs that as argument
zeroptr(&i)
fmt.Println("zeroptr:", i)
fmt.Println("Poiner:", &i)
}