数据类型
// 布尔类型
bool
//字符串
string
//整型
int int8 int16 int32 int64
//无符号整型
uint uint8 uint16 uint32 uint64 uintptr
//字节
byte // alias for unit8
//
rune // alias for unit32,represents a Unicode code point
//浮点型
float32 float64
//复数类型
complex64 comples128
- Go语言不支持隐式数据类型转换
- 别名和原有类型也不能进行隐式类型转换
类型的预定义值
- math.MaxInt64
- math.MaxFloat64
- math.MaxUint32
指针类型
- 不支持指针运算
- string是值类型,其默认的初始化值为空字符串,而不是nil
字符串是数值类型
package type_test
import "testing"
//alias
type MyInt int64
func TestImplicit(t *testing.T) {
var a int = 1
var b int64
//b = a
b = int64(a)
var c MyInt
c = MyInt(b)
t.Log(a,b,c)
}
func TestPoint(t *testing.T) {
a := 1
aPtr := &a
//aPtr = aPtr + 1
t.Log(a,aPtr,*aPtr)
t.Logf("%T %T",a,aPtr)
}
func TestString(t *testing.T) {
var s string
t.Log("*" + s +"*")
t.Log(len(s))
if s == ""{
t.Log("s is empty")
}
网友评论