Package main//non-comment area a line to introduce a packet, the name of this package must be Mainimport "FMT" import "unsafe" func main () {//This is my first go program FMT. Println ("This is my first Go programma"); MYFUNC1 ()//variable//MYFUNC2 ()//constant//MYFUNC3 ()//Operator functest ()//function}//function functest () {}//return maximum func max (A, b int) int {}//operator func myFunc3 () {//Other operators in the Go Language: & (given the actual address of the variable)/* (is a pointer variable) var a = ten var b int32 = var c float32 var D *int FMT. Printf ("A is of type:%t\n", a); int FMT. Printf ("A is of type:%t\n", b); Int32 FMT. Printf ("A is of type:%t\n", c); Float32 FMT. Printf ("A is of type:%t\n", D); *int d = &a fmt. Println ("A's address:", D)//0xc04200e0b0 (influenced by a number of factors) fmt. Printf ("A has a value of:%d\n", a)//10 FMT. PRINTF ("D address stores a value of:%d", *d)//10}//variable var a = 4var b int = 6//All variables defined, do not modify its value outside the function://Syntax error:non-declaration statement Outside function body//a = 444var c Boolvar j,k = "JJJ", "KKK" var p,q = +, "QQQ" func myFunc1 () {//This can only be in the body of a function without declaring D: = 777 A = 444//If only definitions are not used within the function, the compilation error is reported: Y declared and not used//y: = "Fafafa" FMT. Print (A,b,c,d,"\ n")//444 6 false 777 FMT. Print (p,q,j,k, "\ n")//30 QQQ jjj KKK fmt. Println (The value of "J:", J, "; K", "K")//jjj KKK//Exchange two number of values j,k = K,j fmt. Println ("Value of J:", J, "K" Value: ", k)//kkk jjj}//constant func myFunc2 () {///constant Use const ConA =" AAA "Const CONB =" BBB "Const CO Nc,cond = 888, "DDD"//Cannot assign to ConA//ConA = "AAA" FMT. Println ("ConA:", unsafe. Sizeof (ConA)); Cona:16//cona:16 (the first field is a pointer to the string, the second field is the length of the string, each field occupies 8 bytes, but does not contain the contents of the string pointed to by the pointer, which is why sizeof always returns 16)/* * One, if X is a slice , the size that sizeof returns is the descriptor size (24) of the slice, not the size of the memory that the slice points to. * Second, if x is an array, (sizeof is always evaluated at compile time, not at run time, which means that sizeof's return value can be assigned to a constant) sizeof is compiling the evaluated compile value, which means that the memory size of the array can be obtained because the array always indicates its capacity at compile time. And in the future are immutable. * Third, if x is a string, regardless of how large the string len is, sizeof always returns 16, because the string type corresponds to a struct, the struct has two fields, the first field is a pointer to the string, the second field is the length of the string, and each domain occupies 8 bytes. However, the contents of the string that the pointer points to are not included. */FMT. Println (Cona,conb,conc,cond)//aaa BBB 888 DDD//enumeration (iota is a special constant that, when each keyword const appears, is set to 0, and before the next const appears, each occurrence of a iota, its value will automatically increase by 1) const (it0 = Iota//0 it1 = Iota//1 it2 = IoTA//2) const IT3 = Iota//0 fmt. Println ("Iota Test:", It0, It1, it2, it3); Const (I0 = Iota//0 i1//1 i2//2) fmt. PRINTLN ("Enumeration test I0,I1,I2:", i0,i1,i2); Const (AA1 = Iota//0 aa2//1 aa3//2 aa4 = "Hei"//hei aa5//hei aa6 = 100 Aa7//100 aa8 = Iota//7 aa9//8)//Discover an interesting phenomenon: when enumerating, if you do not assign a value to a variable, the preceding value is assigned to the variable by default, and the Iota will The previous base increments by 1, even if no iota fmt appears in other expressions. Println ("Aax:", aa1,aa2,aa3,aa4,aa5,aa6,aa7,aa8,aa9); See again an interesting phenomenon of const (i = 1 << Iota j = 3 << iota k l) fmt. Println ("I j K L:", i,j,k,l)//1 6 12 24}