This is a creation in
Article, where the information may have evolved or changed.
No-sniff Go basics programming
1, can only declare variables or types outside the method, cannot execute statements, such as assignment (declaring and assigning values to the declaration), or control statements (this is the same as Java, be careful!). ), 2,testab: = 10000 The short form of a variable cannot specify a type. And this method can only be used inside methods, cannot be used outside the method 3, a variable can omit a type only if it is declared and assigned a value. If you assign a value after the preceding declaration, you cannot omit the type 4, the declaration of global variables can not omit Var 5, forcing the type conversion to get a value, how to use this to assign a value to this variable does not matter can use: =, can also use var testvar int =. The type of assignment must be the same.
6, declare variables in parallel, constants, if you want to specify, you can specify only one type, at the end of the declaration specified. And all the variables are of this type. 7, single quote constant, go default processing into integers such as ' A ' value is 65
8, constants are named with uppercase letters, and if you do not want to be accessed outside the package, you can add an underscore or lowercase c to be a constant . 9, pointer-related content & get the address of the variable (must have a variable to get) * access to target object by pointer /** Complex Structure **/ type datastruct struct {
Data1Int64
Data2byte
Data3int32
}
/*
Pointer content output for complex structures
*/
vardata
var points *datastruct = &data //Get the address of the variable
varpointspoints**datastruct=&points
varpointspointspoints***datastruct=& Pointspoints
Fmt. Println (pointspointspoints)
Fmt. Println (*points)// Get target object by pointer
Fmt. Println (&data)
Fmt. Println (& (POINTS.DATA1))
Fmt. Println (& (POINTS.DATA2))
Fmt. Println (& (POINTS.DATA3))
varvar1Int64=
varvar2int8=
varvar3byte=
varvar4int16=
varvar5uint64=
/*
pointer content output for basic data types
*/
var point1 *int64 = &var1
var point2 *int8 = &var2
var point3 *byte = &var3
var point4 *int16 = &VAR4
varpoint5*uint64=&var5
Fmt. Println (VAR1)
Fmt. Println (POINT1)
Fmt. Println (VAR2)
Fmt. Println (Point2)
Fmt. Println (VAR3)
Fmt. Println (POINT3)
Fmt. Println (VAR4)
Fmt. Println (POINT4)
Fmt. Println (VAR5)
Fmt. Println (POINT5)