Go Language Learning Series 1

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

installation of 1.1GO languages
Link: Http://pan.baidu.com/s/1hsjkmSO Password: 5m1f
And then all the way crazy dot install ...
Finally, in CMD

Successfully installed ...
Sequential programming of 1.2GO languages
Well, the go language and C + + languages are a little different.
1.2.1 declaration: first embodied in the Declaration of the variable
C:int x;
Go:var x int
C:int x, y, Z;
go:var{
x int
y int
z int
}
The following points are provided:
A.go The curly braces on the left side of the language must follow the same line. You can't start a different line.
The declaration of a variable in the Go language does not have a trivial type of private,public such as the C/C + + variable, and in the Go language, the first letter of the variable is the private attribute if it is lowercase. If it is a function, it is declared as inline, and if it cannot be inline, it is declared as static. Uppercase is the equivalent of public and global .... This is a very important property ...
B. Differences in declarations and definitions: a declaration simply declares a symbol, does not really occupy storage space, and the definition actually consumes a certain amount of bytes in memory.
C. Well, for C, that's not true ..... The C language declares a variable that must occupy some bytes on the function stack frame ... The declaration in Go is a declaration and does not take up the number of bytes.
1.2.2 Definition
C:int x = 10;
GO:
var x = 10//automatic derivation of int type
var x int = 10
x: = 10//Automatic Deduction: = Only for definition and initialization, if the left symbol is defined, an error will be compiled.
It's time to say a few more times.
A.go language is a strongly typed language, like C language, there is no characteristic of the so-called weakly typed language ....
B.Multi-assignment function。。。。 The envy of the C + + programmer
X1,X2....XN = Y1,y2,y3...yn
A statement like the one above is a function of multiple assignments ... Well, what's the use of multiple assignments .... Convenient programming, such as x, y = y,x, this can be done with a simple sentence to exchange two number of functions. Cool, huh?
C.returns multiple function values, maybe this part of the C + + people can feel the benefits of this kind of thing, for the C + + language, if you want the function to return more than one value, or what structure returns a struct or a pointer or a reference as a parameter, which greatly increases the readability of the program. If you have used Matlab or other languages, you will know the benefits of returning multiple return values from the function.
And for go, that's exactly what this feature is.
function declaration
function GetName () (Firstname,lastname,name string) {
Return "AAA", "BBB", "CCC";
}
and receive the third argument can be written like this
,, name = GetName ()
1.2.3 Constants
A. Literal constants such as 10,10.0, "HelloWorld" or something that has been written dead, or thatliteral constants, their type is untypedAnd, uh, what's the advantage? This is mainly because the go language does not provide implicit type conversions, and in their eyes, even the uint and int cannot be converted automatically, unless the programmer automatically uses the coercion type conversion (the method is exactly like the C language). This timeif the constant 10 represents an int type, then it cannot be assigned to a variable of type UINT!!! Unless a forced type conversion is added.
B. The assignment of a constant is a compile-time thing, so the return value of a function cannot be given to a constant. Well, the exact explanation can be explained as well. Because the constants are stored in the. Rodata section, specifically want to understand the self-cultivation of the programmer to read, that book has certain implications, and for the data on the paragraph is a certain embodiment in the executable file, or, after compiling the link, this thing must be written dead written to the executable file. So naturally it has to be determined at compile time. (Core: Related to the storage location of constants)
C. special variables, True,false,itoa;
Just say the itoa.
const{
x = Itoa
Y
Z
x = 0 y = 1 z =2 so .... Automatic growth, this thing is nothing.
.......
* * Bitwise OPERATION: **go in the language is ^x
The new type:complex table complex type ....

Related Article

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.