Pointers in Go
Go supports pointers, which allow you to reference the memory address of a variable. You can declare a pointer using the * symbol, and you can access the value of the variable using the * operator.
var a int = 42
var b *int = &a // b is a pointer to a
fmt.Println(*b) // prints 42
*b = 10 // change the value of a through the pointer
fmt.Println(a) // prints 10
No comments:
Post a Comment