'init'
This commit is contained in:
22
main/project.go
Normal file
22
main/project.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import "fmt" //导入别的包 先执行别的包里面 再执行自己包里面
|
||||
|
||||
//做变量初始化
|
||||
|
||||
// 后是 init函数 全局变量再执行,main函数调用
|
||||
|
||||
var num int = test()
|
||||
|
||||
func test() int {
|
||||
fmt.Println("test")
|
||||
return 10
|
||||
}
|
||||
func init() {
|
||||
fmt.Println("1")
|
||||
|
||||
}
|
||||
func main() {
|
||||
fmt.Println("2")
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user