Data Types ### Go language learning
Data type conversion
1.Go language does not allow implicit type conversions (display conversion can)
2. aliases and original type can not be implicit type conversion
example:
func TestImplicit(t *testing.T){
var a int = 1
var b int64
//b = a //a和b数据类型不一致,隐式转换就失败
b = int64(a) //显式转换才可以
t.Log(a, b)
}
Pointer types
1 does not support pointer arithmetic
example:
//指针不能运算
func TestPoint(t *testing.T){
a := 1
aPtr := &a //指针就是取a的地址
//aPtr = aPtr + 1 错误,指针不能进行运算
t.Log(a, aPtr)
}
2.string are value types, the default is an empty string, not nil
example:
//空字符串初始值为string,并不是nil
func TestString(t *testing.T){
var s string //定义一个字符串类型的值s
t.Log("*"+s+"*") //看这值是否为 **
t.Log(len(s)) //查看s的长度,为0
}