Created
March 5, 2024 04:27
-
-
Save albertocavalcante/03c3e812b980003e46f06878d3758218 to your computer and use it in GitHub Desktop.
Go: Playing with Pointers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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