美文网首页
Go语言学习笔记-基本程序结构-数据类型

Go语言学习笔记-基本程序结构-数据类型

作者: noonenote | 来源:发表于2019-04-09 14:50 被阅读0次

数据类型

// 布尔类型
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

  1. Go语言不支持隐式数据类型转换
  2. 别名和原有类型也不能进行隐式类型转换

类型的预定义值

  1. math.MaxInt64
  2. math.MaxFloat64
  3. math.MaxUint32

指针类型

  1. 不支持指针运算
  2. 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")
        }

相关文章

  • Go的基础知识

    go语言学习笔记 一. 基本结构,基本数据类型 1. 文件名、关键字与标识符 Go 的源文件以 .go 为后缀名存...

  • 笨办法学golang(三)

    这是Go语言学习笔记第三篇。 Go语言学习笔记参考书籍「Go语言圣经」以及Go官方标准库 Go语言基本类型主要有布...

  • Go语言学习笔记-基本程序结构-数据类型

    数据类型 Go语言不支持隐式数据类型转换 别名和原有类型也不能进行隐式类型转换 类型的预定义值 math.MaxI...

  • 02. Go语言程序结构

    Go语言程序结构 一、Go语言程序元素 1). 标识符 标识变量、函数、自定义程序实体。 预定义标识符:数据类型:...

  • Go语言学习笔记-基本程序结构

    基本结构 应用程序入口 必须是main包:package main 必须是main方法:func main() p...

  • 初识Go语言-1

    Go语言学习路径 初识Go语言 Go语言环境搭建与IDE安装 Go语言基础语法 Go语言数据类型 Go语言变量和常...

  • 无标题文章

    今天讲了c语言程序格式,基本数据类型,c语言程序结构。 c语言程序格式一般为 #include int main(...

  • 02-Go语言常量和变量

    Go语言的数据类型 C语言的数据类型 Go语言的数据类型 Go语言各数据类型占用内存空间 Go语言中也可以使用si...

  • Go语言标准库之JSON编解码

    Go语言标准库之JSON编解码 基本的类型 Go语言中的数据类型和JSON的数据类型的关系 bool -> JSO...

  • Go语言标准库之JSON编解码

    Go语言标准库之JSON编解码 基本的类型 Go语言中的数据类型和JSON的数据类型的关系 bool -> JSO...

网友评论

      本文标题:Go语言学习笔记-基本程序结构-数据类型

      本文链接:https://www.haomeiwen.com/subject/tkldiqtx.html