mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-22 20:56:02 +03:00
874d7b4987
Signed-off-by: Bruce <weichou1229@gmail.com>
27 lines
584 B
Go
27 lines
584 B
Go
package pointer
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestBasic(t *testing.T) {
|
|
answer := 42
|
|
fmt.Println(&answer) // & is address operator
|
|
|
|
address := &answer
|
|
fmt.Println(*address) // * is dereferencing, which providers the value that a memory address refers to.
|
|
fmt.Printf("address is a %T \n", address) // print the pointer type
|
|
|
|
var address2 *int // declare a pointer
|
|
address2 = address // address2 can store some pinter type
|
|
fmt.Println(*address2)
|
|
|
|
}
|
|
|
|
func TestPointer(t *testing.T) {
|
|
var test *string = new(string)
|
|
*test = "123"
|
|
fmt.Println(test)
|
|
}
|