Skip to content

Instantly share code, notes, and snippets.

@dacr
Created March 28, 2025 09:02
Show Gist options
  • Save dacr/63204c85b62ab4abf95b01bf208fc89b to your computer and use it in GitHub Desktop.
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/fc90853ade1e1e61c041e7897b109e848d171f4e
/*?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 NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// 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