说明:
- 一次就懂,帮你彻底明白【go】指针 * 和 &,指针和地址
- var jingzhi *abc 只是一个指针变量,只是被声明,但没有初始化,也没赋值,就好像是嗯~,汽车的框架图,对,一张图纸
- 当初始化了就是一个标准的汽车了,算是实体了存在了,这个世界有汽车了
- 赋值,就好像是私有化了,个性化化,这是你的车了(jingzhi 的),然后这个值,具体的值就好像是,我给车里边的放了一个小兔子装饰品
- 我举的例子,可以参考第二份代码
package main
import (
"fmt"
)
type abc struct {
high float64
}
func main() {
var jingzhi *abc
fmt.Printf("jingzhi T = %T, v = %v\n", jingzhi, jingzhi)
jingzhi = new(abc)
fmt.Printf("jingzhi T = %T, v = %v\n", jingzhi, jingzhi)
jingzhi.high = 1.81
fmt.Printf("jingzhi T = %T, v = %v\n", jingzhi, jingzhi)
}
package main
import (
"fmt"
"time"
)
type benChi struct {
colour string
decoration string
seatCover string
}
func main() {
var jingzhiDeBenChi *benChi
fmt.Printf("jingzhi T = %T, v = %v\n", jingzhiDeBenChi, jingzhiDeBenChi)
jingzhiDeBenChi = new(benChi)
fmt.Printf("jingzhi T = %T, v = %v\n", jingzhiDeBenChi, jingzhiDeBenChi)
jingzhiDeBenChi.colour = "酷酷的黑色"
jingzhiDeBenChi.decoration = "装饰品我放了很多娃娃,有可爱的小兔子,还有很多手办,有刻晴,凝光,神里"
jingzhiDeBenChi.seatCover = "没想好要什么座椅套"
fmt.Printf("jingzhi T = %T, v = %v\n", jingzhiDeBenChi, jingzhiDeBenChi)
}