Go语言 - Hello world

2018-01-11  本文已影响7人  louyang

与C语言类似,Go程序也是从main函数开始运行,但是这个main函数必须定义在main package中。(Go语言中的package,类似于C语言中的library)

package main

import "fmt"

func main() {
    fmt.Println("hello world")
}

运行Hello world有两种方法:
方法一,由编译器运行:

$ go run hello.go
hello world

方法二,编译出可执行文件后,再执行:

$ go build hello.go
$ ./hello
hello world

参考
https://golang.org/ref/spec#Program_execution
https://gobyexample.com/hello-world
https://www.golang-book.com/books/intro/11

上一篇 下一篇

猜你喜欢

热点阅读