27 lines
517 B
Go
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)
|
|
}
|