go variables and scope

Here Insert Picture Description
The figure of the same address 1,2,4

  • x:=1Equivalent to first declare a variable x, then the assignment 1;
  • x,err=f(1)So consistent is equivalent to the assignment address
  • x,err1:=f(4)The statement did not report the error is repeated because the back has a new err1, so the compiler will re-think the statement is behind the variable err1, just in front of the x assignment only, so the address will be the same

3,5 address is not the same

  • 3 xx,err:=f(3)is equivalent to declare and assign a new variable xx, the address would become;
  • The reason is to address inconsistencies in {5}, related to the scope and go, will give priority to look for within the block, the block can not be found again in order to find the outside
Published 48 original articles · won praise 56 · views 20000 +

Guess you like

Origin blog.csdn.net/zhetmdoubeizhanyong/article/details/102711959