Skip to content

Instantly share code, notes, and snippets.

@albertocavalcante
Created March 5, 2024 04:27
Show Gist options
  • Save albertocavalcante/03c3e812b980003e46f06878d3758218 to your computer and use it in GitHub Desktop.
Save albertocavalcante/03c3e812b980003e46f06878d3758218 to your computer and use it in GitHub Desktop.
Go: Playing with Pointers
package main
import "fmt"
func main() {
var a int
var b *int
a = 50
b = &a
fmt.Printf("'a' value: %v\n", a)
fmt.Printf("'b' deref value / equal to 'a' value: %v\n", *b)
fmt.Printf("'a' address: %v\n", &a)
fmt.Printf("'b' pointer value / equal to 'a' address: %v\n", b)
fmt.Printf("'b' pointer address: %v\n", &b)
// reassign 'a' value
*b = 100
fmt.Printf("'a' value: %v\n", a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment