Golang basics - Variables

1. Introduction variables

  Variable memory equivalent to a data storage space of representation, you can be seen as a variable room of the house number, street number we can find a room by the same token, you can access the variable (value) by the variable name.

2, quick start, see a case

 

 

 Export

 

 

 3. Note the variables used

  1) denotes a variable storage region in the memory

  2) The region having its own name (variable name) and type (data type ) diagram:

  

4, the variables used in three ways Golang

  If the assignment after a specified variable type declaration, use the default value: (1) The first

   

  (2) The second: The value of the variable type discretion (push type)

  

 

 

   (3) omit var, attention : = variable on the left should not be declared in place, otherwise it will cause a compiler error

  

 

 

   (4) multi-variable declaration

  

  How to declare more than one time in [globals go in function external variables is defined in the global variable]

  

 

 

   5 data values ​​of the changing region may be (key) within the same type range

  

 

 

   (6) In the same scope variables must be unique (in a block of code or function) within  

  

  (7) variable = variable name + value + data type, which please note that the three elements of variables
  (8) Golang variable if no initial value, the compiler will use the default value, such as int default value 0 string defaults empty string, decimal default is 0

5, variable declaration, initialization and assignment

  

 

 6, the program using the +

  1) When both sides are numeric, do the adder
  2) When both sides are strings, the strings do splicing

 

   

 

Guess you like

Origin www.cnblogs.com/Essaycode/p/12640174.html