Skip to content

Instantly share code, notes, and snippets.

@ercang
Last active November 30, 2021 21:32
Show Gist options
  • Save ercang/18b4d5c0ff86496a726c2e9ca8abda07 to your computer and use it in GitHub Desktop.
Save ercang/18b4d5c0ff86496a726c2e9ca8abda07 to your computer and use it in GitHub Desktop.
Simple pointer escape example
package main
import "fmt"
func main() {
var pointerToInt *int = ReturnStackVariable()
fmt.Printf("Here is the number! %v\n", *pointerToInt)
}
func ReturnStackVariable() *int {
localVariable := 10
return &localVariable
}
@ercang
Copy link
Author

ercang commented Nov 30, 2021

In order to see the output of the pointer escape example, please compile with the following option.

go build -gcflags=-m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment