Go Language Learning notes a basic variable

Source: Internet
Author: User
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!!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.