Skip to content

Instantly share code, notes, and snippets.

@codeliger
Created January 12, 2020 00:40
Show Gist options
  • Save codeliger/8c95c738f3604704b2e8c6c3f997f7ca to your computer and use it in GitHub Desktop.
Save codeliger/8c95c738f3604704b2e8c6c3f997f7ca to your computer and use it in GitHub Desktop.
package main

import "fmt"

func Normal(s string) string {
    fmt.Println(&s)
    return s
}

func PointerNormal(s *string) string {
    fmt.Println(s)
    return *s
}

func PointerPointer(s *string) *string {
    fmt.Println(s)
    return s
}

func main() {

    // Normal
    fmt.Println("Normal")
    ain := "Hello World"
    fmt.Println(&ain)

    aout := Normal(ain)
    fmt.Println(&aout)

    // Pass Pointer and Return Normal
    fmt.Println("Pointer In Normal Out")
    bin := "Hello World"
    fmt.Println(&bin)

    bout := PointerNormal(&bin)
    fmt.Println(&bout)

    // Pass Pointer and Return Pointer
    fmt.Println("Pointer In Pointer Out")
    cin := "Hello World"
    fmt.Println(&cin)

    cout := PointerPointer(&cin)
    fmt.Println(cout)
}
Normal
0xc000010200
0xc000010220
0xc000010210
Pointer In Normal Out
0xc000010230
0xc000010230
0xc000010240
Pointer In Pointer Out
0xc000010250
0xc000010250
0xc000010250
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment