This is a creation in Article, where the information may have evolved or changed.
by looking at the Goclipse document finally set up the environment, this note is the process of their own learning, for their own review and exchange, I hope we have a lot of guidance:
First Go program:
Package Mainimport ("FMT"//We need to use the printf () function in the FMT package) Func main () {FMT. Printf ("Hello World for Jackliang")}
The main points of interpretation:
1. Package indicates the packages that go code belongs to
2. To generate a go executable, you must create a main () function (you cannot substitute parameters or define return values)
3. All functions in go voice must start with the keyword func
4, the Go Program code comments and C + + consistency:
/* Block Comment *///// Line Comment
variables and variable declarations
The go variable is declared differently than C and C + +, and the Go voice introduces the keyword Var, and the type information is followed by the variable name as follows:
var v1 int var v2 string var v3 [10]int//array var v4 []int//Array tile var v5 *int//pointer var v6 map[string] int//map,key is of type string, value is int type var v7 func (a int) int var v8 struct { f int}
variable declaration does not require a semicolon as a terminator
Another use of the VAR keyword: put several declared variables together:
var { v1 int v3 string}
Initialization of variables
var v1 int =10var v2=10v3:=10 //compiler can automatically derive its type
1, for the variable declaration to initialize the scene, the Var keyword can be preserved, but is no longer necessary elements!!!! “
2. If the variable that appears on the left side should not have been declared, the error will be compiled as follows :
var test int test:=100000
compile run found Error!!!!
No new variables on left side of: =helloworld.go/helloworld/src/mainline 9Go problem
To Be Continued!!!