awesome-patterns/playground/basic/address_test.go

41 lines
789 B
Go
Raw Permalink Normal View History

2018-09-24 04:12:35 +03:00
package basic
import (
"fmt"
"testing"
)
func TestPrintAddress(t *testing.T) {
var a int
fmt.Printf("%T, %v, %p \n", a, a, &a)
passByVariable(a)
passByPointer(&a)
}
func passByVariable(a int) {
fmt.Printf("%T, %v, %p \n", a, a, &a)
}
func passByPointer(a *int) {
fmt.Printf("%T, %v, %p \n", a, a, &a)
fmt.Printf("%T, %v, %p \n", *a, *a, &*a)
}
type robot struct{}
func TestStructAddress(t *testing.T) {
var a robot
fmt.Printf("%T, %v, %p \n", a, a, &a)
passStructByVariable(a)
passStructByPointer(&a)
}
func passStructByVariable(a robot) {
2018-10-08 16:08:58 +03:00
fmt.Printf("[passStructByVariable] %T, %v, %p \n", a, a, &a)
2018-09-24 04:12:35 +03:00
}
func passStructByPointer(a *robot) {
2018-10-08 16:08:58 +03:00
fmt.Printf("[passStructByPointer] %T, %v, %p \n", a, a, &a)
fmt.Printf("[passStructByPointer] %T, %v, %p \n", *a, *a, &*a)
2018-09-24 04:12:35 +03:00
}