pointers in golang

99

var ap *int
func main () {
  b := *getPointer()
  fmt.Println("Value is", b)
}
package main

import "fmt"

func main() {
	// create a normal string variable
	name := "original"
	// pass in a pointer to the string variable using '&'
	setName(&name, "boot.dev")
	fmt.Println(name)
}

func setName(ptr *string, newName string) {
	// dereference the pointer so we can modify the value
	// and set the value to "boot.dev"
	*ptr = newName
}

Comments

Submit
0 Comments