整理
-
go build yu.go
建立exe檔案
./yu
執行檔案 -
go run main.go
於commandline 執行檔案做測試 -
go doc fmt
查看套件用法
go doc fmt.Println
查看此套件中的方法用法 -
const earthsGravity = 9.80665
定義常數變數 -
amount, unit := 10, "doll hairs"
可以同時定義兩個變數且不同型態 -
空字串、空數字
1 | package main |
Println
vsPrint
1 | package main |
- 使用
%v
, usePrintf
1 | package main |
%T
is Type%d
is integer%f
is float, ex: 3.500000%.2f
is float, ex: 3.50- 使用
Sprintln
帶入參數並利用Println
印出字串
1 | package main |
1 | package main |
.Scan()
to get user input
1 | package main |
- random number
1 | package main |
- address use
&
1 | package main |
- Pointers are variables that specifically store addresses.
var pointerForInt *int
pointerForInt
will store the address of a variable that has anint
data type.
1 | lyrics := "Moments so dear" |
1 | func addHundred(num int) { |
1 | func addHundred (numPtr *int) { |