Last active
February 3, 2026 20:19
-
-
Save dacr/63204c85b62ab4abf95b01bf208fc89b to your computer and use it in GitHub Desktop.
go pointers / published by https://github.com/dacr/code-examples-manager #c4cdd92d-c11b-4e88-8090-2b2d00926bd0/7d0ffc6cd431081fc986e662060ba6c854356712
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
| /*?sr/bin/true; exec /usr/bin/env nix-shell -p go --run "go run $0" #*/ | |
| // summary : go pointers | |
| // keywords : go, pointers, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : c4cdd92d-c11b-4e88-8090-2b2d00926bd0 | |
| // created-on : 2025-03-27T11:01:31+01:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : nix-shell -p go --run "go run $file" | |
| package main | |
| import "fmt" | |
| func main() { | |
| var ptr *string // nil by default | |
| //*ptr = "crash" ! | |
| value := "blabla" | |
| ptr = &value | |
| fmt.Println(*ptr) | |
| value2 := *ptr | |
| *ptr = "bouhhh!!!!!!!!!!!!!!!!!" | |
| fmt.Println(value) | |
| fmt.Println(value2) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment