Go by Example - Pointers
Go by Example - Pointers
com/pointers
Go by Example: Pointers
Go supports pointers, allowing you to pass
references to values and records within your
program.
package main
import "fmt"
We’ll show how pointers work in contrast to values func zeroval(ival int) {
with 2 functions: zeroval and zeroptr. zeroval has ival = 0
an int parameter, so arguments will be passed to }
it by value. zeroval will get a copy of ival distinct
from the one in the calling function.
func main() {
i := 1
fmt.Println("initial:", i)
zeroval(i)
fmt.Println("zeroval:", i)
1 of 1 11/26/24, 23:34