摘要:
Go has pointers, but no pointer arithmetic.Struct fields can be accessed through a struct pointer. The indirection through the pointer is transparent.... 阅读全文
摘要:
Struct fields are accessed using a dot.package main import "fmt"type Vertex struct { X int Y int}func main() { v := Vertex{1, 2} v.X = 4 ... 阅读全文
摘要:
Astructis a collection of fields.(And atypedeclaration does what you'd expect.)package main import "fmt"type Vertext struct { X int Y int}func ... 阅读全文
摘要:
As a simple way to play with functions and loops, implement the square root function using Newton's method.In this case, Newton's method is to approxi... 阅读全文
摘要:
Variables declared inside anifshort statement are also available inside any of theelseblocks.package main import ( "fmt" "math")func pow(x, n, ... 阅读全文
摘要:
Likefor, theifstatement can start with a short statement to execute before the condition.Variables declared by the statement are only in scope until t... 阅读全文
摘要:
Theifstatement looks as it does in C or Java, except that the( )are gone and the{ }are required.(Sound familiar?)package main import ( "fmt" "m... 阅读全文
摘要:
If you omit the loop condition it loops forever, so an infinite loop is compactly(简洁地;紧密地;细密地) expressed.package main func main() { for { ... 阅读全文
摘要:
At that point you can drop the semicolons(分号): C'swhileis spelledforin Go.package main import "fmt"func main() { sum := 1 for sum < 1000 { ... 阅读全文
摘要:
As in C or Java, you can leave the pre and post statements empty.package main import "fmt"func main() { sum := 1 for ; sum < 1000; { sum... 阅读全文
摘要:
Go has only one looping construct, theforloop.The basicforloop looks as it does in C or Java, except that the( )are gone (they are not even optional) ... 阅读全文
摘要:
Numeric constants are high-precisionvalues.An untyped constant takes the type needed by its context.Try printingneedInt(Big)too.package main import "f... 阅读全文
摘要:
The expressionT(v)converts the valuevto the typeT.Some numeric conversions:var i int = 42var f float64 = float64(i)var u uint = uint(f)Or, put more si... 阅读全文
摘要:
Go's basic types areboolstringint int8 int16 int32 int64uint uint8 uint16 uint32 uint64 uintptrbyte // alias for uint8rune // alias for int32 ... 阅读全文
摘要:
Inside a function, the:=short assignment statement can be used in place of avardeclaration with implicit type.Outside a function, every construct begi... 阅读全文
摘要:
A var declaration can include initializers, one per variable.If an initializer is present, the type can be omitted; the variable will take the type of... 阅读全文
摘要:
Thevarstatement declares a list of variables; as in function argument lists, the type is last.package main import "fmt"var i intvar c, python, java bo... 阅读全文
摘要:
A function can return any number of results.This function returns two strings.package mainimport "fmt"func swap(x, y string) (string, string) { ret... 阅读全文
摘要:
import后面接的是目录的名字,而不是所谓包的名字,并且如果一个目录下面还有目录的话都必须要写进去,比如:import "MyPackage"import "MyPackage/MyInnerPackage"在这里讲明白了import后面接的是目录名而不是文件名更不是所谓的包名,那么一个目录下面的... 阅读全文
摘要:
安装Go语言开发环境实例代码 - 详述Go语言安装所在需要的工作:安装C语言工具,安装Mercurial,更新go到新版本等操作实例。安装go环境1、简介Go是一个开源项目,采用BSD授权协议。 该文档介绍如何获取Go源代码,如何编译,以及如何运行Go程序。目前有两种方式使用Go语言。这里主要讲述如... 阅读全文