1 variables three kinds of declaration: ( the first kind of Var and type are redundant;
the second is the most concise, but the second can only be used in a function, not the declaration of a global variable.
The first type:
var v_name V_type ( note order = value
" FMT " Func Main () { varint 123 Fmt. Println (vname1) FMT. Println (vname2) FMT. Println (Vname3)}
Second type: (initialization declaration)
If you are in the same code block, we cannot use the initialization declaration again for variables of the same name
var= value ( self-derived type )
" FMT " Func Main () { var789 FMT. Println (v1) FMT. Println (v2) FMT. Println (v3)}
The third type:
: = Value (: = The variable on the left must be not declared )
2 value types and reference types
All basic types, such as int, float, bool, and string, are value types, using variables of these types to point directly to a value that exists in memory, and when an equal sign is used to =
assign the value of a variable to another variable, such as: j = i
, the value of I is actually copied in memory
&i to get the memory address of the variable I, for example: 0xf840000040 (each time the address may be different). The value of a variable of value type is stored in the stack.
。
Lesson Five Golang language variables