You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
940 B

3 years ago
package main
import "fmt"
/**
newmake:
1.
2. makeslicemapchannel
3. new
*/
func main() {
a := 10
b := &a
fmt.Printf("%v, %p\n", a, b)
fmt.Printf("a: %T, b: %T\n", a, b)
fmt.Printf("%v\n", *b)
modify1(a)
fmt.Printf("%v\n", a)
modify2(&a)
fmt.Printf("%v\n", a)
//Go中 引用类型的比变量不仅不要声明,还需要对其分配内存空间,否则将无法存储
//而值类型则不需要分配内存空间
//var m *int //未分配内存空间
m := new(int)
*m = 150
fmt.Println(*m)
//var mm map[string]int//为分配内存空间
mm := make(map[string]int)
mm["123"] = 1233
fmt.Println(mm)
}
func modify1(num int) {
num = 20
}
func modify2(num *int) {
*num = 100
}