# 变量定义
使用var关键词,变量类型卸载变量名之后
```
var a,,b,v bool
var s1,s2 string ="hello","go"
```
可以放在函数内,或直接放在包内
使用var()集中定义变量
```
var (
a int
b bool
)
```
编辑器自动决定类型
```
var f,g, h = 2,true,"h"
```
使用:=定义变量,尽量使用该方式定义。只能在函数内使用
```
var f,g, h := 2,true,"h"
```
# 数据类型
> bool,string
> (u)int,(u)int8,(u)int16,(u)int32,(u)int64,uintptr
> byte,rune
> float32,float64,complex64,complex128
没有char,只有rune
原生支持复数类型
# 数据类型转换
```
var a,b int =3,4
var c int =int(math.Sqrt(float64((a*a+b*b))))
```
# 定义
```
const file string ="abc.txt"
```
const数值可以作为各种类型使用
```
const a,b = 3,4
```
```
var c int=math.Sqrt(a*a+b*b)
```
# 特殊常量-枚举类型
## 普通枚举类型
```
const (
cpp=1
php=2
java=3
)
```
## 自增值枚举类型
```
const (
cpp1=iota
php2
java3
)
const (
b=1<<(10*iota)
kb
mb
gb
tb
pb
)
```
# 一个main函数搞定所有
```
package main
import "fmt"
func main() {
var v_name_int int = 1
var v_name = 2
v_name_ := 3
var (
v1_string string = "this is v1"
v2 bool = true
v3_min int = -9223372036854775808
v3_max int = 9223372036854775807
v4_uint8_min uint8 = 0
v4_uint8_max uint8 = 255
v4_uint16_min uint16 = 0
v4_uint16_max uint16 = 65535
v4_uint32_min uint32 = 0
v4_uint32_max uint32 = 4294967295
v4_uint64_min uint64 = 0
v4_uint64_max uint64 = 18446744073709551615
v4_int8_min int8 = -128
v4_int8_max int8 = 127
v4_int16_min int16 = -32768
v4_int16_max int16 = 32767
v4_int32_min int32 = -2147483648
v4_int32_max int32 = 2147483647
v4_int64_min int64 = -9223372036854775808
v4_int64_max int64 = 9223372036854775807
v5 byte = 'a'
v6_float32 float32 = 2.2
v6_float64 float64 = 2.2
//定义指针*运算符不仅能取值,还可以对指向变量值
p *int
p1 = 12
//通过&运算符可以获取指针所指向地址的值
p_addres = &p1
//通过*运算符可以获取变量地址的原始数据,叫解引用
p_value = *p_addres
)
const c1 = "this is const"
}
```