Golang quando usar ponteiros

Exemplos de código

0
0

Ponteiros em golang

func main () {
  b := *getPointer()
  fmt.Println("Value is", b)
}
0
0

golang ponteiro

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
}

Em outros idiomas

Esta página está em outros idiomas

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................