package main
import (
"fmt"
)
//--1
//声名布尔型变量
//var isGoodBoy = true //真
//var isGoodBoy = false //假
var isGoodBoy bool
//--2
//声名数值型变量
//var age int = 60
var age int
//var rmb float32 = 0.5
var rmb float32
//--3
//声名复数型变量
//var vector complex64 = 3+4i
var vector complex64
//--4
//声名字符串变量
//var name string = "李峰"
var name string
//--5
//声名复合型变量
//固定长度的整形数组
//var eggs [8]int = [8]int}{1,2,3,4,5,6,7,8}
var eggs [8]int
// 可变长的整形 叫切片
//var heights []int = []int{1,2,3,4,5}
var heights []int
//--6
//映射 (键1:值1,健2:值2)
//var kpi map[string]int = map[string]int{"代码量":1000,"注释量":3000}
//var haha map[string]float32 = map[string]float32{"资产":123.12}
//var hehe map[string]float32 = map[string]float32{"资产":123.12,"负债":678.34}
var info map[string]float32
var kpi map[string]int
//--7
//结构体
//var telangpu struct{
// name string
// age int
// rmb float32
//}
var person struct{}
//--8
// 整形指针
var weight int = 300
var weightPointer *int = &weight
//--9
//声名函数变量
//var eat func() = func() {
// fmt.Println("我是个吃货")
//}
var eat func()
func main() {
/*
fmt.Printf格式化打印
%T 类型占位符
%v 值占位符
*/
fmt.Println("打印 go 数据类型的默认值..")
fmt.Printf("【1-布尔型变量】的类型是%T,值是%v\n",isGoodBoy,isGoodBoy)
fmt.Printf("【2-数值型变量-整形】的类型是%T,值是%v\n",age,age)
fmt.Printf("【2-数值型变量-浮点型】的类型是%T,值是%v\n",rmb,rmb)
fmt.Printf("【3-复数型变量】的类型是%T,值是%v\n",vector,vector)
fmt.Printf("【4-字符串变量】的类型是%T,值是%v\n",name,name)
fmt.Printf("【5-复合类型-固定长度的整形数组】的类型是%T,值是%v\n",eggs,eggs)
fmt.Printf("【5-复合类型-可变长度的整形数组】的类型是%T,值是%v\n",heights,heights)
fmt.Printf("【6-映射键值】的类型是%T,值是%v\n",info,info)
fmt.Printf("【7-结构体】的类型是%T,值是%v\n",person,person)
fmt.Printf("【8-整形指针】的类型是%T,值是%v\n",weightPointer,weightPointer)
fmt.Printf("【9-函数变量】的类型是%T,值是%v\n",eat,eat)
}
输出内容:
打印 go 数据类型的默认值..
【1-布尔型变量】的类型是bool,值是false
【2-数值型变量-整形】的类型是int,值是0
【2-数值型变量-浮点型】的类型是float32,值是0
【3-复数型变量】的类型是complex64,值是(0+0i)
【4-字符串变量】的类型是string,值是
【5-复合类型-固定长度的整形数组】的类型是[8]int,值是[0 0 0 0 0 0 0 0]
【5-复合类型-可变长度的整形数组】的类型是[]int,值是[]
【6-映射键值】的类型是map[string]float32,值是map[]
【7-结构体】的类型是struct {},值是{}
【8-整形指针】的类型是*int,值是0x12c6250
【9-函数变量】的类型是func(),值是<nil>
有疑问加站长微信联系(非本文作者)